A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearConvert US date format to ANSI SQL date format (YYYY-mm-dd) - page 1
User InfoPosts
Convert US date format to ANSI SQL date format (YYYY-mm-dd)#1
I want to convert user-submitted date format (mm/dd/yyyy) to a MySQL date format (YYYY-mm-dd). Submission is via a simple PHP form direc tto MySQL database.

posted date: 2008-12-09 17:28:00


Re: Convert US date format to ANSI SQL date format (YYYY-mm-dd)#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-09 17:28:01


Re: Convert US date format to ANSI SQL date format (YYYY-mm-dd)#3
$mysql_date = date('Y-m-d H:i:s', strtotime($user_date));

posted date: 2008-12-09 17:30:00


Re: Convert US date format to ANSI SQL date format (YYYY-mm-dd)#4
An alternative method as of PHP 5.2$datetime = new DateTime($user_date);echo $datetime->format('Y-m-d H:i:s');DateTime is Y38k and timezone friendly.

posted date: 2013-01-29 18:17:00


Re: Convert US date format to ANSI SQL date format (YYYY-mm-dd)#5
A further method, this time on the SQL side is to use the convert method in your sql query: CONVERT(VARCHAR(11),$user_date,111) //e.g. SELECT CONVERT(VARCHAR(11),DATEFIELD,111) AS DATE //or SET DATEFIELD = CONVERT(VARCHAR(11),'".$user_date."',111)See: http://www.w3schools.com/sql/func_convert.asp - the number at the end changes the type of date format, with 111 returning: 2006/12/30.

posted date: 2014-01-07 18:54:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.