Insert DATE TIMESTAMP value in MySQL using PHP

Using php I am inserting or updating a mysql database with a creation date or a modified date using variables

$datestring = "%Y:%m:%d %h:%i:%s"; $time = time(); $createdate= mdate($datestring, $time); 

This $createdate will use the variable that I use to insert or update the table. But this update is of the wrong value. This is not server time or local time. Basically this is a 30 minute delay with a time server.

+4
source share
3 answers

Use date function () PHP

 $createdate= date('Ymd H:i:s'); 
+10
source

Edit: after some searches, it looks like you are using CodeIgniter. You should have mentioned this in your question.

The format string used does not match the MySQL date format. Do you want to use:

 $datestring = '%Y-%m-%d %H:%i:%s'; 
+1
source

use in mysql query like DATE_FORMAT (purchaseDate, "% Y:% m:% d% h:% i:% s") function

0
source

Source: https://habr.com/ru/post/1306199/


All Articles