Trouble using DATEDIFF

User, date Message
Written by geragera
5 years ago
Category: General
1 posts since Thu, 31 Jan 08
Hi everybodyhappy,
i just start using SQL and i have a trouble using DATEDIFF in HeidiSQL. i have one date '2007-12-27' and i trying to obtain how many months and days are of difference between that date and Today(CURRENT_DATE()) i´m trying have this result:

1 month 4 days
because today is Juanary 31 2008

i'm trying to use DATEDIFF("m",2007-12-27,CURRENT_DATE()) but i cant use this syntaxis.

i just can use DATEDIFF(2007-12-27,CURRENT_DATE()) and this command only returns me the number of days

i hope you can help me.thanks
Written by ansgar
5 years ago
3958 posts since Fri, 07 Apr 06
You could divide the result of DATEDIFF by 30, that would give you a rough result. But I guess you want the exact months and days, as different months have a different number of days. That should be done with some application logic, not SQL.
Written by siMKin
5 years ago
104 posts since Sun, 01 Apr 07
with the command TO_DAYS you can convert the date to an amount of days and substract one from the other in that way, so the result will also be in days
 

Please login to leave a reply, or register at first.