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...
-
Add results from database in form address
PHP - MySQL
First post
Hello Coursesweb
I have a problem to get results from the database into input type text form in the place name.
name= id='. $row1 ....
Last post
Marplo thanks thanks thanks for all suport
& even so quick suport `thanks again`
it is working
I could kiss you :D
-
Get ID after insert with PDO
PHP - MySQL
First post
Hello Coursesweb,
I asking for longer time myself how to get the ID after an insert into database with pdo.
<?php
if(isset($_POST )){...
Last post
To get the id after an Insert with pdo, use the lastInsertId() method.
$sql = INSERT INTO tracker_comment...