Ok so this isn’t really very impressive for a blog post, but I am curious if anyone has a more sensible way to do this.
The DateTime struct understands, seconds, minutes, hours, days, months, years, etc. However, I find it kind of odd that the DateTime struct doesn’t understand “quarters”. Quarters of a year are a common concept in any finance application and unlike weeks they are not all the same length.
What I need to determine is the start and end dates of the quarter for the current date minus one month. There are a million ways I could do this:
- I could just have a helper class with the 4 start date of the quarter and have it do comparisons. Seems a bit overkill to have a class.
- I could just compare the
DateTime.Monthvalue to values 1, 4, 7, 10 to figure out which quarter I am in and then set the start and end dates. This is nice and simple. - Instead I did this:
1 2 3 4 5 6 7 8 | |
mmmmm… mod math ;-). Ok so it isn’t that cool, but I’m sure I’m going to need to use this again.
Chris
Edit: Fixed my total failure with brackets.