Reputation: 41
I have to insert the current date in my table after finished traitement for this I use this code
date_default_timezone_set('Europe/Paris');
//Don't forget this..I had used this..just didn't mention it in the post
$datetime_variable = new DateTime();
$test = date_format($datetime_variable, 'Y-m-d H:i:s');
$sqld = "insert into Traitement (dateTraitement) values (date_format($datetime_variable, 'Y-m-d'))";
$stmtd = sqlsrv_query( $conn, $sqld);
if( $stmtd === false ) {
die( print_r( sqlsrv_errors(), true));
}
but it gives me this Error:
Object of class DateTime could not be converted to string in
However, my dateTraitement in my table is datetime.
Upvotes: 1
Views: 1018
Reputation: 963
mysql_query("INSERT INTO `table` (`dateposted`) VALUES (GETDATE())");
you can use GETDATE() function and add today date that's it
Upvotes: 1
Reputation: 41
i solved the problem by only using this request
insert into DateTraitement (dateTraitement) values (SYSDATETIME())
thinks for your helps
Upvotes: 0
Reputation: 1615
if you want insert current date.then you can use NOW()
your query should be
insert into Traitement ('dateTraitement') values (now())
Or you can use this also
insert into Traitement ('dateTraitement') values (CURRENT_TIMESTAMP())
if you are using sql server then you can use GETDATE()
insert into Traitement ('dateTraitement') values (GETDATE())
Upvotes: 0