Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting DATETIME to a human readable date

Tags:

php

datetime

I'm trying to convert the DATETIME to something that people can actually use. This is the date:

2013-09-05 11:52:10

I'm using:

date("D, d M Y", '2013-09-05 11:52:10');

Is turning into:

Thu, 01 Jan 1970

Makes no sense to me.

like image 386
dcolumbus Avatar asked Dec 11 '22 22:12

dcolumbus


2 Answers

You need to turn the date into a timestamp before passing it to date()

$time = strtotime('2013-09-05 11:52:10');
echo date("D, d M Y", $time);
like image 86
Bugs Avatar answered Dec 14 '22 10:12

Bugs


Is this supposed to be PHP code? If so, the correct is

date("D, d M Y", strtotime('2013-09-05 11:52:10'));

If this has to do with MySql, the correct function to use is DATE_FORMAT (however, what you have is invalid MySql syntax). Please clarify.

like image 34
Jon Avatar answered Dec 14 '22 11:12

Jon