This question already has an answer here:
I'm now inserting a date/time
data into my date/time field
in the database. I have tried many techniques such as:
$date = date("d M Y");
$date = date("d M Y", mktime());
$date = getdate();
$date = date("d M Y", strtotime('now'));
and also this function: date_default_timezone_set('Asia/Bangkok');
but it still does not get the datetime.
This is my sql statement:
$sql = "INSERT INTO ".TABLE_CONTENT."(`title`, `detail`, `crdate`, `modate`, `crby`, moby, isdel) VALUES('".$title."', '".$detail."', '".$crdate."', '".$modate."', '".$crby."', '".$moby."', $isdel)";
After performing the query I got only the 0000-00-00 00:00:00
in my database.
Any help or suggestion would be very appreciated.
Thanks
</div>
Looks like your database fields are set to timestamp, so you'll have to insert data into the database fields in exactly that format.
So this would work
$date = date('Y-m-d H:i:s');
You could also use the MySQL NOW()
, which would insert the current timestamp into that field, although the timezone would be set to whatever timezone your server is on.
example:
$sql = "INSERT INTO <table> (title, crdate) VALUES ('test', NOW())";