sammcd75
sammcd75

Reputation: 21

PHP date and time to Mysql datetime

Im trying to get the current time in PHP using $sTime = date("Y-m-d H:i:s"); and store it in a mysql table in a datetime column like: $sTQuery = "INSERT INTO Actions(UserID, StartDuration) VALUES ('$UserID' , '$sTime')";

The date echos as expected but in the table it just shows 0000-00-00 00:00:0.

I have tried using now() in the query but still get 0000-00-00 00:00:0 in the table.

Edit: In the mysql table the column the date and time is to be stored in is a datetime

Upvotes: 0

Views: 70

Answers (1)

A.D.
A.D.

Reputation: 2372

Try to use this query... This contains DateTime value by now() as per your need.

$sTQuery = "INSERT INTO Actions(UserID, StartDuration) VALUES ('$UserID' ,now())";

Upvotes: 1

Related Questions