Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Function to get number of days in month Rate Topic Display Mode Topic Options
Author
 Message
 Posted Thursday, April 28, 2011 7:15 AM
 SSC Veteran Group: General Forum Members Last Login: Thursday, October 31, 2013 7:56 AM Points: 247, Visits: 410
 Well played!Slope (4/27/2011)Of course, if you use a calendars table you never have to worry about having to code or validate any date calculations ever again. Sure makes life a lot simpler. Here is how I would get that answer:`SELECT d.DaysInCalendarMonthFROM dbo.dwCalendars dWHERE d.CalendarDate = @SomeDate`
Post #1100210
 Posted Thursday, April 28, 2011 7:22 AM
 Ten Centuries Group: General Forum Members Last Login: Thursday, January 31, 2013 8:01 AM Points: 1,232, Visits: 1,046
 Obs (4/28/2011)Well played!Slope (4/27/2011)Of course, if you use a calendars table you never have to worry about having to code or validate any date calculations ever again. Sure makes life a lot simpler. Here is how I would get that answer:`SELECT d.DaysInCalendarMonthFROM dbo.dwCalendars dWHERE d.CalendarDate = @SomeDate`Only if the Calendars table was created using a LOT differant math than the one presented for this function.
Post #1100215
 Posted Thursday, April 28, 2011 7:17 PM
 Old Hand Group: General Forum Members Last Login: Tuesday, December 03, 2013 5:44 PM Points: 353, Visits: 516
 Back when school was cool (and storage expensive!) they taught us not to store calculated information.I suspect that all of the functions presented here are lower cost than a read.
Post #1100687
 Posted Monday, May 02, 2011 12:34 AM
 Valued Member Group: General Forum Members Last Login: Wednesday, November 27, 2013 11:48 AM Points: 57, Visits: 515
 how to give any mnth to the above query?
Post #1101447
 Posted Monday, May 02, 2011 3:04 PM
 SSC Rookie Group: General Forum Members Last Login: Thursday, October 10, 2013 3:53 AM Points: 39, Visits: 17
 Does anyone noticed this logic:Month < 8 AND month <> 2 => days_in_month = 30 + (month & 1)Month >= 8 => days_in month = 30 + ((month+1) & 1)Of course, there is standard for the February
Post #1101958
 Posted Monday, June 13, 2011 6:50 AM
 Forum Newbie Group: General Forum Members Last Login: Monday, January 21, 2013 3:15 PM Points: 2, Visits: 17
Post #1124221
 Posted Monday, June 13, 2011 12:21 PM
 Forum Newbie Group: General Forum Members Last Login: Today @ 10:55 AM Points: 8, Visits: 139
 ramanamreddy (5/2/2011)how to give any mnth to the above query?Apologies for the late reply:`SELECT DISTINCT d.DaysInCalendarMonthFROM dbo.dwCalendars dWHERE d.CalendarYear = 2011AND d.CalendarMonthName = 'February'`
Post #1124510
 Posted Monday, June 20, 2011 5:21 AM
 Valued Member Group: General Forum Members Last Login: Monday, December 02, 2013 10:37 AM Points: 71, Visits: 410
 This one doesn't work unless the @testdate is the 1st day of the month. E.g. with @testdate = '2011-01-30' it incorrectly returns 29.
Post #1128097
 Posted Monday, June 20, 2011 7:07 AM
 Ten Centuries Group: General Forum Members Last Login: Thursday, January 31, 2013 8:01 AM Points: 1,232, Visits: 1,046
 EITCL (6/20/2011)This one doesn't work unless the @testdate is the 1st day of the month. E.g. with @testdate = '2011-01-30' it incorrectly returns 29.There are several things wrong with the information in the article.There are many posts in the discussion thread that show better ways of converting a date.
Post #1128212
 Posted Thursday, September 01, 2011 7:54 AM
 Forum Newbie Group: General Forum Members Last Login: Wednesday, September 18, 2013 1:10 PM Points: 1, Visits: 160
 If you change the last bit of the case to:else case when ((Year(@day) % 4 = 0) and ((Year(@day) % 100 != 0) or (Year(@day) % 400 = 0)))you will perform fewer tests. With ((A and B) or C), both A and C have to be evaluated even when A is false. When changed to (A and (B or C)), B and C are only evaluated when A is true.
Post #1168670

 Permissions