You can, sort of. You can use a type of query like this:
select if(now()>'2005-04-28', 1, 0);

Which will return a 1 or a 0 if the date is greater than the current date/time. But that's a very weak comparison, prone to error, since the date must be in the MySQL readable format. So while you could use MySQL to validate a date, I wouldn't.

Use javascript validation only as a user interface convenience. Never rely on in for validating input to your database. Always assume the data you are receiving did not come from something you made. You should use the programming or scripting language (i.e. PHP, Perl) you are using, to validate the data and format it properly.

On Apr 29, 2005, at 11:00 AM, Anoop kumar V wrote:

Is it possible to do a date field validation using an sql query.

Its like we have an html field- its a free form text field and the end user
should type in a valid date, of course in a predefined format only
(MM/dd/yyy). I tried using javascript but either it works on some browsers
and not in others or the user can just disable javascript in eth browser.


SO I was hoping that I can use an sql query (some function in mysql) which
will return true or false based on whether the date is in the future, valid
(considering leap years etc..) and in the predefined format.


Is this possible - is it a viable thing to do - all I want is a foolproof
way of validating the date input field.


--
Thanks and best regards,
Anoop

--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to