datetime format
Moderator: General Moderators
-
playwright
- Forum Newbie
- Posts: 20
- Joined: Wed Jun 02, 2010 6:11 pm
datetime format
Hello!! i want to save datetimes into a mysql database. Their format is dd-mm-yy hh:mm. I think mysql format for datetime is yy-mm-dd hh:mm..How can i convert them??
Re: datetime format
Pull apart "their" format so you have a variable for the year, a variable for the month, etc. Then re-arrange them with string concatenation.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: datetime format
Try using strtotime, and then recreating the date in MySQL format using the php date() function. You may have to do str_replace to switch the hyphens with slashes, since sometimes strtotime doesn't recognize the datetime format you're using. But 9 times out of 10 it will give you the correct date from any reasonable format.