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
?
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.
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.
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.
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.
$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
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