Welcome to WebmasterWorld Guest from 54.224.57.95

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

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?

Thanks
-Brandon
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?

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

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month