How to find last month first date and last month last date ?
Solution:
Select
DateAdd(M,(DateDiff(M,0,GetDate()-1)),0)As [First Date],
DateAdd(M,(DateDiff(M,-1,Getdate()-1)),-1)as [last date]
DateAdd(-,-,-):
It will take 3 values and which is used to add no.of days or months or years to a given date.
First value- Date part
Second value- Numeric value
Third value -Date
DateDiff(-,-,-):
It will also take 3 values and which is used to find the difference between two dates, in terms of days,months and years.
First value- Date part
Second value - Start Date
Third value - End Date
Solution:
Select
DateAdd(M,(DateDiff(M,0,GetDate()-1)),0)As [First Date],
DateAdd(M,(DateDiff(M,-1,Getdate()-1)),-1)as [last date]
DateAdd(-,-,-):
It will take 3 values and which is used to add no.of days or months or years to a given date.
First value- Date part
Second value- Numeric value
Third value -Date
DateDiff(-,-,-):
It will also take 3 values and which is used to find the difference between two dates, in terms of days,months and years.
First value- Date part
Second value - Start Date
Third value - End Date
No comments:
Post a Comment