Last Updated: February 25, 2016
·
433
· k2t0f12d

Date Format

At some point I wanted to get just the date and part of the time from a timestamp column. So I:

left(convert_tz(EventTime,'+00:00','system'), 15)

Which works in MySQL from the terminal, but in Java-based SQL managers like Squirrel you get:

32  30  31  32  2d  30  36  2d  32  31  20  30  34  3a  34

To work around this, or simply to write more bulletproof SQL scripts, wrap your query in a dateformat function, like:

left(date_format(convert_tz(EventTime,'+00:00','system'), '%Y-%m-%d %H:%i:%S'), 15)

2012-06-21 04:4