0

I am trying to convert a date in words Mar 02 2018 to a timestamp and convert it back to the original format(Mar 02 2018)

This is because I want the users to input date in this format then it is save to the database as a timestamp so that the sql statement ORDER BY timestamp DESC can work. And then on display shows the original format which it was inputted.

I have seen some similar post but not the exact format of date I want and not vice versa.

Thanks for your input. Also if it isn't converted to timestamp would the sql statement still order it properly or I need to convert it to timestamp??

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • `Also if it isn't converted to timestamp would the sql statement still order it properly`...no it wouldn't. Store dates in a proper DateTime field in the database, not as text or numeric or anything else, then sorting and filtering will work correctly – ADyson Jul 14 '21 at 23:30
  • `convert it back to the original format`...see https://www.php.net/manual/en/function.date.php – ADyson Jul 14 '21 at 23:31
  • Just use PHP's DateTime class to convert the date between formats. The date should be stored as DateTime field in the database too. I don't know why you would want to use a timestamp anywhere – Dharman Jul 14 '21 at 23:41

0 Answers0