1

In my client's MySQL database, the following timestamp is saved and I am unable to convert it to date and time because it is invalid.

20211024090000

echo date('m/d/Y H:i:s', 20211024090000);

this code results in:

11/09/642431 23:20:00

But it should be 2021 year. I am sure that the timestamp is correct, I just can't figure out what type it is so I can convert it correctly.

lwd
  • 37
  • 6
  • It is not a timestamp, it is a mutilated datetime string. You should convert the values to a new column of datetime type, move these values to that column, formatted correctly, and drop this column. It is close to ISO format which would be something like `2021-10-24 T 09:00:00`. Could use https://regex101.com/r/fk7psH/1/ to break it apart. – user3783243 Oct 17 '21 at 15:19
  • https://www.php.net/manual/en/datetime.createfromformat.php – splash58 Oct 17 '21 at 15:32
  • Does this answer your question? [Saving timestamp in mysql table using php](https://stackoverflow.com/questions/5632662/saving-timestamp-in-mysql-table-using-php) – rustyhu Oct 18 '21 at 06:52

0 Answers0