Hi
I have a string which contains the year and month, now i wanted to know what is the starting day of that month in that particular year.
For Ex: string STR = "Jan\2006" then by any chance i can know the starting day of this month as whether it is Sunday etc. I need the string "sunday" as output. Also, I need to know how many number of days that particular month contains. Any function or stored procedure which will give out these two outputs will be much appreciated.
Thanks!
Santhosh
SQL Server has some built in functions to accomodate this functionality. Look at DateName and DatePart in Books On Line.
Here's an example to get you started.
Declare @.Temp VarChar(20)
Set @.Temp = 'Jan\2006'
Select DateName(Weekday, Convert(DateTime, '01-' + Replace(@.Temp, '\', '-'))) As StartingWeekday,
Day(DateAdd(day, -1, DateAdd(Month, 1, Convert(DateTime, '01-' + Replace(@.Temp, '\', '-'))))) As DaysInMonth
No comments:
Post a Comment