Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting date to human readable format

Lets say in my mysql database I have a timestamp 2013-09-30 01:16:06 and lets say this variable is $ts.

How can I output this to show more like September 30th, 2013?

like image 975
soniccool Avatar asked Oct 03 '13 06:10

soniccool


People also ask

How do I convert a date to a readable format?

The toLocaleDateString() method can be used to get a formatted date in the local language and country. The toLocaleDateString() method takes two arguments, the first one is the language code and the second one is the format of the date. The language code could be: en-US - Sunday, January 1, 2012.

How do I convert a date to a character?

You can use the as. Date( ) function to convert character data to dates. The format is as. Date(x, "format"), where x is the character data and format gives the appropriate format.

How do you format a date in mm dd yyyy?

dd/MM/yyyy — Example: 23/06/2013. yyyy/M/d — Example: 2013/6/23. yyyy-MM-dd — Example: 2013-06-23. yyyyMMddTHH:mmzzz — Example: 20130623T13:22-0500.

How do I display a date in a specific format?

The dates appear as, mm/dd/yyyy in the U.S. and as, dd/mm/yyyy outside the U.S. where mm is the month, dd is the day, and yyyy is the year. The time is displayed as, hh:mm:ss AM/PM, where hh is the hour, mm is minutes, and ss is seconds.


1 Answers

$timestamp = "2013-09-30 01:16:06"; echo date("F jS, Y", strtotime($timestamp)); //September 30th, 2013 

Note the use of S to get the english ordinal suffix for the day.
Since you're already using strtotime if you need a human readable data for the current time you can just use the keyword "now" as in strtotime("now")

Related sources

  • Date
  • strtotime
like image 173
Juan Cortés Avatar answered Sep 17 '22 20:09

Juan Cortés