Hi all,
I am a little weak at SQL, so bear with me.
Can anyone give me an SP which uses "Between" to Display all Dates
BETWEENa fromDate and toDate?
Two conditions
1.Both Dates are stored asvarchar.
2. I should be able to get the dates even if years are different, say between 20th December 2006 and 3rd January 2007
3.Is there a way to extract the yearDiff?
Regards,
Naveen
Hi
Try Datediff function in SQLSERVER
Bye
|||You can use DateDiff as stated by deepakleo however there's a few things you need to make sure takes place.
1. Need to make sure that since your dates are being stored as varchar that they are being stored in a format that can be cast as datetime.
2. You need to cast them as datetime to determine the date diff.
datediff("YYYY", Cast('December 20 2006' as datetime), Cast('January 3 2007' As DateTime))
The above will give you the difference in years between the 2 dates. If you want the difference in dates then use "dd" instead of "YYYY" and "mm" for the difference in months.
No comments:
Post a Comment