0

How to get a format of the given date or time in php?

If I give date like this,

2022-03-08 06:45:06

It should return "Y-m-d H:i:s"

Is there any possible way to get the format from date?

Jass
  • 61
  • 1
  • 6
  • 1
    No, you cannot get the format of the date. The reason: PHP cannot know what is the day or the month for the first 12 days. "03" kan be either month or day. – Gert B. Mar 29 '22 at 08:05

1 Answers1

-1

i dont think there is such a function.

if you need to handle dates in different formats, reformat them in timestamp and then in the needed format

you can try something like this

  $timestamp = strtotime("2022-03-08 06:45:06");
  $newFormat = date('Y-m-d', $timestamp)
benkov
  • 184
  • 9
  • 1
    They didn't ask how to format the date, they want to know the format of a date string. Completely different. In the question, they already have it in this format so why would they need to reformat it? – M. Eriksson Mar 29 '22 at 07:59