Sql server Date Diff
-
Hi, all select convert(varchar,(datediff(dd,'1979-09-04 12:34:50.603',getdate())/365)) here getdate()='2007-09-05 12:34:50.603' I need find the age of employee but this result is showing 28 instead of 27 because till one day is required to complete 27... Praveen Kumar
-
Hi, all select convert(varchar,(datediff(dd,'1979-09-04 12:34:50.603',getdate())/365)) here getdate()='2007-09-05 12:34:50.603' I need find the age of employee but this result is showing 28 instead of 27 because till one day is required to complete 27... Praveen Kumar
How are you getting the age, Are you using DATEDIFF ?
Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture) http://www.frankkerrigan.com/[^]
-
Hi, all select convert(varchar,(datediff(dd,'1979-09-04 12:34:50.603',getdate())/365)) here getdate()='2007-09-05 12:34:50.603' I need find the age of employee but this result is showing 28 instead of 27 because till one day is required to complete 27... Praveen Kumar
Try something like this for a more accurate result:
SELECT YEAR(GETDATE()) - YEAR('1979-09-04 12:34:50.603') - CASE WHEN DATEPART(dayofyear,GETDATE()) < DATEPART(dayofyear,'1979-09-04 12:34:50.603') THEN 1 ELSE 0 END AS Age
-
Hi, all select convert(varchar,(datediff(dd,'1979-09-04 12:34:50.603',getdate())/365)) here getdate()='2007-09-05 12:34:50.603' I need find the age of employee but this result is showing 28 instead of 27 because till one day is required to complete 27... Praveen Kumar
Why do you use
DATEDIFF(YY, @tartdate, getdate())
Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture) http://www.frankkerrigan.com/[^]