Jump to content


Insert date to database


  • Please log in to reply
1 reply to this topic

#1 nanie

  • Members
  • PipPip
  • Member
  • 10 posts

Posted 09 October 2013 - 01:53 AM

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,


//check date format here before continuing.

echo $final_date; // to see the conversion

and this is what i get back

Warning: mktime() expects parameter 5 to be long, string given .....................

Please help me, I want to get this value -----> 09/10/2013

#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 17,666 posts

Posted 22 October 2013 - 07:08 PM

$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

Edited by Barand, 22 October 2013 - 07:11 PM.

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users