homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

php date format conversion
Converting a date submitted through a form

 11:59 pm on Mar 18, 2013 (gmt 0)

I have a form input that accepts a date and inserts it into a MySQL database. The current format is YYYY, MM-DD. This is the format that I require on one of the forms that allows the user to input a date range for a custom report. I'm going to replace the manual input with a graphical calendar using jquery but it's been requested that I change the date formate to MM/DD/YYYY.

In a nut shell, how can I convert MM/DD/YYYY to YYYY, MM-DD so the database will recognize it?




 12:41 am on Mar 19, 2013 (gmt 0)

Maybe this will help

$date = '01/24/2006';
echo date('Y-m-d', strtotime($date)); // outputs 2006-01-24


 12:54 am on Mar 19, 2013 (gmt 0)

Thanks Skorpios,

I have to pass the date variable back to an sql statement, so could I do this:

$date = '01/24/200';
$new_date = date('Y, m-d', strtotime($date));

And then use $new_date in my sql statement instead of $date?



 12:03 pm on Mar 19, 2013 (gmt 0)

Looks about right, did you try it? Also, why not just use the ISO date format as your database table column definition? It would be an easy adjustment right away and you can then use all kinds of date features during SELECT queries. It will make your life much easier I would think!


 12:13 pm on Mar 19, 2013 (gmt 0)

MM/DD/YYYY is ambiguous for non-US readers for the first 12 days of every month.

YYYY-MM-DD is never ambiguous (yyyy-dd-mm is not used anywhere).

See also RFC 3339.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved