Page 1 of 1
datetime format
Posted: Thu Jul 29, 2010 10:06 am
by playwright
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
Posted: Thu Jul 29, 2010 10:20 am
by pickle
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.
Re: datetime format
Posted: Thu Jul 29, 2010 12:18 pm
by jraede
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.