Small date issue
Moderator: General Moderators
Small date issue
I've read the manual on php.net and evidently I'm too tired to get it right now. I've got a user form where the user enters a date in mm/dd/yyyy format. How do I convert that to the format that can be written to my MySQL table, which accepts yyyy/mm/dd? Thanks! 
Current Date?
If you are trying to retrieve todays date,
just use the date() function.
http://www.php.net search for date in functions,
Otherwise if you want watever date the user enters to be recorded...
It should insert simply as a string, If you make the table type LONGTEXT... etc
just use the date() function.
http://www.php.net search for date in functions,
Otherwise if you want watever date the user enters to be recorded...
It should insert simply as a string, If you make the table type LONGTEXT... etc
Code: Select all
list ($month, $day, $year) = split ('ї/.-]', $StartDate);
$StartDate = date('Y-m-d',mktime(0,0,0,$month,$day,$year));This will cope with the following input mm/dd/yyyy mm-dd-yyyy or mm.dd.yyyy
Hope this helps
Mike
-
IndyTim
- Forum Newbie
- Posts: 2
- Joined: Thu May 02, 2002 2:49 pm
- Location: Indy,Indy(Indianapolis Area)
Something else to consider, once you've settled in on a date conversion, you might want to build it (and other related date conversions etc.) into a user callable function. That way you'll get heavy re-use as your scripting library increases. I have to deal with conversions from MySQL to Unix to_fro EvilEmpire Short Dates etc. Callable functions definitely simplify things.
IndyTim
IndyTim
