1.How to calculate age
SELECT DATEDIFF(DD,'1981-01-05 00:00:00.000',GETDATE())/365 AS AGE
2.How to calulate first day of previous month
select DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0)
Here 0 indicate as default date of sql(01/01/1900)
3. How to calculate last day of previous month
SELECT GETDATE()-DATEPART(dd,GETDATE())
No comments:
Post a Comment