Jump to content

[SOLVED] Date/time help


tejama

Recommended Posts

Hey all,

 

I'm trying to insert a date/time into Mysql.  I'm entering a future date in a text box similar to '2007-12-31 6:00:00' and the field in Mysql I'm trying to insert it into is of the type datetime.

 

I'm trying

$date = $_POST['date'];

$newdate = date(Y-m-d H:i:s, strtotime($date);

 

Then I try to insert $newdate but no joy.  Can anyone suggest what's going wrong here?

Link to comment
https://forums.phpfreaks.com/topic/55307-solved-datetime-help/
Share on other sites

 

Try this, I think it's because you're missing quotes. Try echoing the query to the page first to see if you're getting the date in the format before trying to enter it. I'm presuming the date is a Unix timestamp too.

 

$newdate = date("Y-m-d H:i:s", strtotime($_POST['date']);

 

EDIT:

Ohhh you're entering the date into a field in the correct format? Then you can just enter it as shown below.

Link to comment
https://forums.phpfreaks.com/topic/55307-solved-datetime-help/#findComment-273398
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.