0

I inherited a really messy, poorly-designed database, and there are certain things I can't change. The timestamp field in the database is a varchar field, which contains data that looks like this: 1595974379 1595977031 1596033136 It's not even a proper date format.

When I output the data on screen, I can tweak it through code to display the actual date:
$transdate = date("Y.m.d",$getLedger->getColumnVal("timestamp"));

However, is there a way to convert ALL of the dates in the database to an actual date instead of having to deal with a date being a varchar field? Is there a way to do this without losing all of the data? I created a new field, called transdate, which IS a date field.

I tried updating that field with data from the timestamp (varchar) field, but it's not working.

UPDATE transactions SET transdate = STR_TO_DATE(timestamp, '%Y-%m-%d') 

I get an error message that says: Incorrect datetime value: '1595974379' for function str_to_date

I would like to take the data from the timestamp field, convert it to an actual date, and move that date into the transdate field.

Thank you!

Dharman
  • 30,962
  • 25
  • 85
  • 135
Blondie
  • 59
  • 5

0 Answers0