Sunday, February 19, 2012

Handle datetime in SQL Server 2005

Are there any function in SQL Server 2005 which can help to calculate the total no. of days and months? Let's said if I provide 2 dates, 28-Feb-2001 and01-Mar-2004, it can return 36 Months and 2 Days. The concept is like the functionmonths_between in Oracle. Are there any function in SQL Server 2005 can achieve this?

You can use DATEDIFF function: for example

DATEDIFF

(m,'1/1/2007',getdate())as monthDiff

DATEDIFF(d,'1/1/2007',getdate())as dayDiff

|||

Try the DateDiff function

|||

try datediff function is very helpfull

Thanks

No comments:

Post a Comment