PHP Date Conversion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
webphotogeek
Forum Newbie
Posts: 18
Joined: Sun Jul 04, 2010 12:11 pm

PHP Date Conversion

Post by webphotogeek »

Can someone tell me how to convert a date such as 8/13/10 into the the MySQL format, such as 2010-08-13 and also the reverse using PHP? I can't seem to find the right functions.

Thanks!
User avatar
arrielmabale
Forum Newbie
Posts: 15
Joined: Fri Aug 13, 2010 3:57 pm
Location: Dubai

Re: PHP Date Conversion

Post by arrielmabale »

//convert to sql
$mDate = 8/13/10
$edate = explode('/',$mDate);
$toSql = '20' + $edate[2] + '-' + $edate[1] + '-' + $edate[0];

##############

//from sql make sure to used UNIX_TIMESTAMP on the field
//then top display
$mdate = date('y/m/d');

i did not see the output, but im sure of this
webphotogeek
Forum Newbie
Posts: 18
Joined: Sun Jul 04, 2010 12:11 pm

Re: PHP Date Conversion

Post by webphotogeek »

Thanks for the reply. I didn't think of using the explode function :)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PHP Date Conversion

Post by Weirdan »

Code: Select all

$mDate = "8/13/10";
$toSql = DateTime::createFromFormat("m/d/y", $mDate)->format("Y-m-d");
Post Reply