This blog summarizes a plenty of programming tricks coming from Allen's practical project experiences, including PHP, C#, Java, Yii Framework, Lucene...
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
"//return 94
ReplyDelete//???"
MySQL is works really strange here. it just:
20101109 - 20101015 = 94