Currently I am retrieving a date from mssql with the data type of small date time.
The data is : 2013-03-12 00:00:00
I want to store it in a variable and then display on a text box.
And the format I want to display is just 2013-03-12
on the text box.
The message I get is:
catchable fatal error : Object of class DateTime could not be converted to string.
Any idea?
in php you can simply use date_format($date, 'Y-m-d')
<?php
$date = date_create('2013-11-23 05:06:07');
echo date_format($date, 'Y-m-d');
?>
returns 2013-11-23
The following code will give you a date usable for SQL:
$dateTime->format(\DateTime::ISO8601);
-edit-
Actually, I just saw that you want it the other way around. In that case:
$dateTime->format('Y-m-d');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With