Saturday 9 March 2013

mysql two datetimes substraction (date difference)

Assume var1, var2 are type of datetime in MySQL:

var1 = 2010-11-09, var2 = 2010-10-15;

select var1 - var2
from tableX
//return 94
//???


select DATEDIFF(var1,var2)
from tableX
//return 25
//25 days between var1 and var2

1 comment:

  1. "//return 94
    //???"
    MySQL is works really strange here. it just:
    20101109 - 20101015 = 94

    ReplyDelete