PHP - Insert date time object in the type of DateTime column in database
Discuss coding issues, and scripts related to PHP and MySQL.
-
PloMar
- Posts:48
PHP - Insert date time object in the type of DateTime column in database
I want to insert a DateTime object in database (created in PHP) where the column type is DateTime. How can I do?
I am using this code:
Code: Select all
$cdate = new DateTime('now');
$cd = $cdate->format('d/m/Y h:i:sa');
$udate = new DateTime('72 hours');
$ud = $udate->format('d/m/Y h:i:sa');
$sql = "INSERT INTO table (name, cd, ud) VALUES ('some_name', '$cd', '$ud')";
MarPlo
Posts:186
Use the "Y-m-d H:i:s" date-time format in PHP, it is the format of the DateTime column in MySQL.
Code: Select all
$cdate = new DateTime('now');
$cd = $cdate->format('Y-m-d H:i:s');
Similar Topics
- Redirect according to browser type
JavaScript - jQuery - Ajax
First post
Pleasant Coursesweb,
I have two `simple` javascript what I wanna combine between detecting in two different browsers to script to another page....
Last post
Marplo thanks for quick feedback took me more hours, I should have come earlier with asking questions.
It is a waste I`m not have experiance with...