nanie Posted October 9, 2013 Share Posted October 9, 2013 Hi, I'm currently using date picker for selecting event date in my form codes. But I have problem when trying to insert to the database. The date picker display value as this, October 9th, 2013 I try to convert it using this code from another forum, $eventDate=$_POST['eventdate']; //check date format here before continuing. list($day,$month,$year)=explode('/',$eventDate); $timestamp=mktime(0,0,0,$month,$day,$year); $final_date=date('Y-m-d',$timestamp); echo $final_date; // to see the conversion and this is what i get back Warning: mktime() expects parameter 5 to be long, string given ..................... 1970-01-01 Please help me, I want to get this value -----> 09/10/2013 Link to comment https://forums.phpfreaks.com/topic/282824-insert-date-to-database/ Share on other sites More sharing options...
Barand Posted October 22, 2013 Share Posted October 22, 2013 $picker = 'October 9th, 2013'; $dt = DateTime::createFromFormat('F jS, Y', $picker); $dbDate = $dt->format('Y-m-d'); echo $dbDate; That will show $dbDate to contain "2013-10-09" which is the format you should be using to write dates to a database table Link to comment https://forums.phpfreaks.com/topic/282824-insert-date-to-database/#findComment-1455011 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.