How to subtract hours from a datetime in MySQL?

后端 未结 2 734
眼角桃花
眼角桃花 2020-11-27 05:40

I get a datetime field, that\'s currently in the query as:

SELECT DATE_FORMAT(x.date_entered, \'%Y-%m-%d\') AS date FROM x ORDER BY date ASC
<
相关标签:
2条回答
  • 2020-11-27 05:53

    mySQL has DATE_SUB():

    SELECT DATE_SUB(column, INTERVAL 3 HOUR)....
    

    but would it not be better to try and sort out the underlying time zone issue instead?

    0 讨论(0)
  • 2020-11-27 06:00

    Assuming you have some timezone issue and know source and destination timezone, you could convert it like so

    SELECT DATE_FORMAT(CONVERT_TZ(x.date_entered, 'UTC', 'Europe/Berlin'),
                       '%Y-%m-%d') AS date
    FROM x ORDER BY date ASC;
    
    0 讨论(0)
提交回复
热议问题