I am retrieving a date from the database in the format YYYYMMDD. It is a wordpress value and has to be stored like this in order for me to perform specific queries with it that work with wordpress.
I want to convert it to no leading zeros day, and short month, e.g. 3 DEC, for 20121203. However php’s date function says it takes a unix timestamp, so I need to convert it to such before I can manipulate it. How can I do this?
strtotimeshould be able to convert that format to a UNIX timestampThis also depends on your locale settings, by the way.
EDIT: Important Note: if a date is ambiguous strtotime returns false!
You can also use the
mktime()function, which accepts integer values for hour, minute, second, month, day, year to produce a unix timestamp:EDIT: Another way is to retrieve the value from the database already formatted (assuming MySQL):