Subtract hours from a datetime in MySQL

0

I have a field which is a datetime, this field returns the following date / time:

2018-05-16 14:37:45

What I would like is to be able to subtract 5 hours from that date and make it look like this:

2018-05-16 09:37:45

I could achieve this with the function of DATE_ADD but I like to believe that there could be another, easier way to achieve what I want. Any other way to make it easier?

DATE_ADD(ov.hora_llegada, INTERVAL -5 HOUR)
    
asked by Hoose 16.05.2018 в 17:51
source

1 answer

1

MySQL has DATE_SUB () :

SELECT DATE_SUB(ov.hora_llegada, INTERVAL 5 HOUR)

And then use it as you wish, for example:

UPDATE prueba SET ov.hora_llegada = DATE_SUB(ov.hora_llegada, INTERVAL 5 HOUR);

If you want to try it first to make sure you're doing what you want:

SELECT ov.hora_llegada, DATE_SUB(ov.hora_llegada, INTERVAL 5 HOUR) FROM prueba;
    
answered by 16.05.2018 / 17:57
source