Subtracting months in .NET (approximately)



  • Spotted this in an ASP.NET application I'm maintaining....

    DateTime SinceDate = DateTime.Now.Subtract(new TimeSpan((30 * 13), 0, 0, 0)); // approx 13 calender months ago

    ...and there's me thinking what's wrong with using this...

    DateTime SinceDate = DateTime.Now.AddMonths(-13); // EXACTLY 13 calender months ago



  •  Maybe there's some reason to assume a 30 day month?

    I never liked the concept of counting things by "months" anyhow, where a "month" is a variable measurement.  Imagine if distances worked that way.  "Well, if you're in Austin, Houston is about 160 miles away and Bastrop is about 33.   But once you're in Bastrop, Houston is only another 20 miles!"



  • @vt_mruhlin said:

     Maybe there's some reason to assume a 30 day month?

    Indeed. The first line of code will return a date 390 days before the current date. The second line will return exactly the same day of the month, but 13 months before the current date.

    @vt_mruhlin said:

    I never liked the concept of counting things by "months" anyhow, where a "month" is a variable measurement.  Imagine if distances worked that way.  "Well, if you're in Austin, Houston is about 160 miles away and Bastrop is about 33.   But once you're in Bastrop, Houston is only another 20 miles!"

    My credit card already does that. It has a promotion where the more I use it, the more "miles" I get that I can use with airlines. However, when I go claiming my miles, it turns out that they either get rounded down to the closest multiple of 1000 or I get to see a table where some amount of miles means traveling to anywhere within the state, a power of 10 more miles means anywhere in the country and another power of 10 means I can travel to neighbouring countries.



  • @vt_mruhlin said:

     Maybe there's some reason to assume a 30 day month?

    I never liked the concept of counting things by "months" anyhow, where a "month" is a variable measurement.  ...

     

     Hmm. How do you feel about a year that is not easily divisible (e.g. the way 360 days would be) ?

     How about 24 hours a day, but 60 minutes an hour? Wouldn't decimal time measurments be better?

     Are you often frustrated by inefficient reality?



  • @richardchaven said:

     Hmm. How do you feel about a year that is not easily divisible (e.g. the way 360 days would be) ?

     How about 24 hours a day, but 60 minutes an hour? Wouldn't decimal time measurments be better?

     Are you often frustrated by inefficient reality?

     

    Yeah, kinda like that quote from Adam from MythBusters. It goes something like "I reject your reality and will substitute my own." 

    Of course what do you expect, everything was user defined when we all started. I don't think reinventing the wheel in this case will make a better wheel. 

     



  •  @richardchaven said:

    Hmm. How do you feel about a year that is not easily divisible (e.g. the way 360 days would be) ?

     How about 24 hours a day, but 60 minutes an hour? Wouldn't decimal time measurments be better?

    Yeah.  I have a theory that the only reason we have the whole 12/24 hour thing is because the aliens who built the pyramids, etc had 6 fingers on each hand so a base 12 number system made more sense to them.  (so they'd love the 360 day year).  Having only 10 fingers myself, I'd greatly prefer a day to be split up into 100 increments.



  • @vt_mruhlin said:

    I'd greatly prefer a day to be split up into 100 increments.

     <hints id="hah_hints"></hints>
    I'm sure it can't be that hard to convince everybody to convert to metric time.  Let's set up a meeting at 46:70 to discuss.



  • @vt_mruhlin said:

    Maybe there's some reason to assume a 30 day month?

    Maybe in some cases (I can't imagine what), but in this case there isn't. To the client 13 months ago means just that, so today is 3rd July 2008, 13 months ago would mean 3rd June 2007, seems logical/common sense to me.

    @vt_mruhlin said:

    I
    never liked the concept of counting things by "months" anyhow, where a
    "month" is a variable measurement.  Imagine if distances worked that
    way.  "Well, if you're in Austin, Houston is about 160 miles away and
    Bastrop is about 33.   But once you're in Bastrop, Houston is only
    another 20 miles!"

    It may be variable, but most APIs/frameworks like .NET are intelligent enough to know the number of days in each month (including 29 days in February during a leap year), so would accurately subtract/add months accordingly, assuming you're subtracting/adding from a specific date in the gregorian calendar.



  • One use of the 30-day month is for mortgage interest calculations. Certain types of loans are calculated based upon 30 day increments for purposes of interest accumulation/pay down.



  • @richardchaven said:

    @vt_mruhlin said:

     Maybe there's some reason to assume a 30 day month?

    I never liked the concept of counting things by "months" anyhow, where a "month" is a variable measurement.  ...

     

     Hmm. How do you feel about a year that is not easily divisible (e.g. the way 360 days would be) ?

     How about 24 hours a day, but 60 minutes an hour? Wouldn't decimal time measurments be better?

     Are you often frustrated by inefficient reality?

    We could switch to the Mayan (long count) calendar, of course ... base-20 metric calendars, the only non-base-20 count would be the month. Oh, and remember that the 13th b'aktun isn't the end of the calendar; it doesn't end in 2012. 😉


  • I liked the system in Exalted (rpg).The year has 420 days, with 15 28-day months. Then there's a "week" (the length of which changes per year) which is basically not in the calendar and is a traditional 'week off' for everyone. This way you have a standard calendar and the people who know how to calculate the necessary calibration days for that year can just tell you "ok, you get 5 days off this year"



  •  @vt_mruhlin said:

    Maybe there's some reason to assume a 30 day month?

    I never liked the concept of counting things by "months" anyhow, where a "month" is a variable measurement.  Imagine if distances worked that way.  "Well, if you're in Austin, Houston is about 160 miles away and Bastrop is about 33.   But once you're in Bastrop, Houston is only another 20 miles!"

    Do you understand that with 30 day months we would end up very quickly having January in the summer on the northern hemisphere? Like, in about 65 years?



  • @DrJokepu said:

    Do you understand that with 30 day months we would end up very quickly having January in the summer on the northern hemisphere? Like, in about 65 years?

     

    Rather in about 32 years, in 65 years it would be back to normal. Anyway, that would be only fair to those in living in the southern hemisphere. Maybe Aussies also want chrismas with snow sometimes?



  • @vt_mruhlin said:

    Yeah.  I have a theory that the only reason we have the whole 12/24 hour thing is because the aliens who built the pyramids, etc had 6 fingers on each hand so a base 12 number system made more sense to them.  (so they'd love the 360 day year).  Having only 10 fingers myself, I'd greatly prefer a day to be split up into 100 increments.

    Some people already tried that 10 years ago. Turn out it didn't work so well,

    Swatch Internet time




  • @ammoQ said:

    Rather in about 32 years, in 65 years it would be back to normal.

    I double checked my calculations, you're right it's 32 years.@ammoQ said:

    Anyway, that would be only fair to those in living in the southern hemisphere. Maybe Aussies also want chrismas with snow sometimes?

    Well, do you?



  • And if we're nitpicking anyway: maybe we shouldn't have any relation between days and years. One day is the time needed for the earth to make one spin, one year is the time needed for the earth to complete a 'circle' around the sun. So if the world would spin faster or slowerwe'd only have to redefine hours and seconds, not years...

     

     Okay, that should be my last beer for today...



  • @DrJokepu said:

    How about increasing the angular speed of the Earth with gigantic rockets so one revolution would be exactly 360 days? That would be the true F/OSS freetard solution.

    Still need to redefine the length of a second a bit, so the new day is 24 * 60 * 60 seconds again, otherwise the measurements on my watch will be off. Oh wait... Dammit... Ok, new watch then...



  • @Kefer said:

    And if we're nitpicking anyway: […] One day is the time needed for the earth to make one spin

     

     More nitpicking: It actually isn’t. Have you ever heard of leap seconds? 🙂



  • @Ren said:

    I liked the system in Exalted (rpg).The year has 420 days, with 15 28-day months. Then there's a "week" (the length of which changes per year) which is basically not in the calendar and is a traditional 'week off' for everyone. This way you have a standard calendar and the people who know how to calculate the necessary calibration days for that year can just tell you "ok, you get 5 days off this year"

    Hmm, I wonder if they borrowed that from the Shire calendar. Twelve months of 30 days, plus two days in the winter (New Year's Eve and New Year's Day) and three (four in Leap Years) days in the summer, all five or six of which were holidays and had no month. To make matters more interesting, the center day plus the leap day had no day of the week, which means that every calendar day has the same weekday each year. Also, the solstices fell on the center day and the beginning of the year, which makes seasons, weeks, and months all come out even. Well, more or less - solstices do move by a few days over the course of the 400-year leap cycle...



  • The easiest calendar to get IMO is the Discworld (a series of comedic fantasy books) one. From the Discoworld Wiki:

    A Discworld year has 800 days and because of some interesting astronomical facts two of each seasons (two summers, two winters, etc.). This leads to the fact that many people actually do not count the astronomical years, but the half-years with 400 days. The half-year has 13 months: Offle, February, March, April, May, June, Grune, August, Spune, Sektober, Ember, December, and Ick. Each month except Ick has 32 days, Ick has 16 days. Each week has eight days. The eighth day of each week is called Octeday.

    There are two main calendars in use on Discworld. The Ankh-Morpork Calendar counts full years and starts at the founding of Ankh-Morpork, the University Calendar starts at the founding of Unseen University (in 1282 AM) and counts in half-years. Oddly enough, while the Imperial Ankh-Morpork calendar offers intellectual purity and mathematical elegance, the general populace tends to use the Weird, Wild, Wacky Wizards' calendar, which happens to correspond to the growing season.

    There, you get the same day of the week for the same month every year, and there are no leap years. Also, the sun and moon always keep the same orbit around the cosmic turtle. It's the disc spinning on the back of the elephants that cause the seasons.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.