Date conversion for DB Insert
Posted: Wed Oct 26, 2005 6:54 pm
I have a form that accepts a date entry. This entry can accept values for just about any date within the last 100 years or so (Dates of Birth). I am hosted on a windows server that seems to choke on negative timestamp values so I have had to resort to a DATE field in the MySQL DB to store the data. Here is what I want to do...
Take a date value in the form "mm/dd/YYYY" and convert it to the form "YYYY-mm-dd". Here's the catch...
Not every user can be trusted to enter the date in the form "mm/dd/YYYY". I have a javascript that restricts the field to that format, but if the user doesn't have Javascript installed or enabled they could feasibly pass anything to the script that is 10 characters long and the script would take it. How should I go about validating this value and changing it to the form "YYYY-mm-dd" so I can insert/update it to the DB?
Take a date value in the form "mm/dd/YYYY" and convert it to the form "YYYY-mm-dd". Here's the catch...
Not every user can be trusted to enter the date in the form "mm/dd/YYYY". I have a javascript that restricts the field to that format, but if the user doesn't have Javascript installed or enabled they could feasibly pass anything to the script that is 10 characters long and the script would take it. How should I go about validating this value and changing it to the form "YYYY-mm-dd" so I can insert/update it to the DB?