MySQL Implications of doing utc_date + 1 rather than using date_add(utc_date, interval 1 day)

StackOverflow https://stackoverflow.com/questions/4885096

  •  28-10-2019
  •  | 
  •  

Frage

I have some queries where day offsets are being coded as utc_date + 1 rather than using the date_add function. Are their any implications of using this method? I'm worried about it returning the wrong result in some circumstances, especially when the result date rolls over to a different month

War es hilfreich?

Lösung

select utc_date()+1, date('2011-02-28')+1, date_add('2011-02-28', INTERVAL 1 DAY)

Using the above query (on MySQL 5.0.51a), I get the following results:

  • utc_date()+1 = 20110204
  • date('2011-02-28')+1 = 20110229
  • date_add('2011-02-28', INTERVAL 1 DAY) = 2011-03-01

So it appears that simply adding 1 to the date causes mysql to treat the date value as an integer and not as a date. I'd recommend changing your code to use date_add.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top