i have column named postDate
defined as timestamp. when i print it directly:
echo $result['postDate'];
i do get that what is stored(eg. 2011-03-16 16:48:24
) on the other hand when i print it through date function:
echo date('F/j/Y',$result['postDate'])
i get December/31/1969
what am i doing wrong?
many thanks
PHP date() format when inserting into datetime in MySQL. This problem describes the date format for inserting the date into MySQL database. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The date can be stored in this format only.
Example: For converting datetime to format – dd:mm:yyyy, you can use the following query: SELECT DATE_FORMAT('2020-03-15 07:10:56.123', '%d:%m:%Y');
try this.
date('F/j/Y',strtotime($result['postDate']));
as timestamp is required, not formatted date as second parameter. or you can also try
SELECT UNIX_TIMESTAMP(postDate) as postDateInt from myTable
instead of SELECT postDate from myTable
and then have this in your code.
date('F/j/Y',$result['postDateInt']);
The PHP date function looks for an int time()
as the 2nd param. Try using strtotime()
echo date('F/j/Y', strtotime($result['postDate']) );
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