G
Guest
i've noticed some strange behavior in .net when it comes to figuring out the previous month via code. this only happens when the month is january, and i know why it's happening, i just don't understand why this issue isn't addressed by .net. we have reports that get run on previous month's data, so that would be december given that it's january. if i do DateTime.Now.Month-1, the result is of course 0, so i get an exception. i have to write code like this to test if it's january
If DateTime.Now.Month = 1 The
Dim monthCounter As Integer = 13 - CInt(strMonthsBack) ' strMonthsBack is the number of months to search bac
lblAETitle.Text = MonthName(monthCounter
Els
lblAETitle.Text = MonthName(DateTime.Now.Month-1
End I
of course this works fine, but it looks messy. i can do this in TSQL like this
DECLARE @REPORT_MONTH DATETIM
SET @REPORT_MONTH=DATEADD(month, -1, GETDATE()
TSQL automatically realizes that it's january, so it rolls it back to december. i know i can accomplish the same thing in .Net using the DateTime.Subtract method, but that involves setting up other DateTime/TimeSpan variables and thus can get just as messy for something this easy. am i missing something? i would think that the .Net runtime would do a quick check on the integer value of Month before proceeding, but it doesn't. any and all comments are greatly appreciated, please email me directly as i won't be monitoring this thread actively
thank
jayson
If DateTime.Now.Month = 1 The
Dim monthCounter As Integer = 13 - CInt(strMonthsBack) ' strMonthsBack is the number of months to search bac
lblAETitle.Text = MonthName(monthCounter
Els
lblAETitle.Text = MonthName(DateTime.Now.Month-1
End I
of course this works fine, but it looks messy. i can do this in TSQL like this
DECLARE @REPORT_MONTH DATETIM
SET @REPORT_MONTH=DATEADD(month, -1, GETDATE()
TSQL automatically realizes that it's january, so it rolls it back to december. i know i can accomplish the same thing in .Net using the DateTime.Subtract method, but that involves setting up other DateTime/TimeSpan variables and thus can get just as messy for something this easy. am i missing something? i would think that the .Net runtime would do a quick check on the integer value of Month before proceeding, but it doesn't. any and all comments are greatly appreciated, please email me directly as i won't be monitoring this thread actively
thank
jayson