And you are even forgetting about the messing with time when switching from 'wintertime' to 'summertime' and back.Calculating the "exact duration" of 2 months is very hard to impossible, as months do not have the same amount of seconds. For example: 31 dec + 2 months... is 31 feb. Also here and there extra seconds are added, thus you get times like: 23:59:62 (62 seconds, when 3 additional seconds are added). You can do compromises, like using days in the range 1-28 and only change the month.
Some more languages:
use Carbon\Carbon; $now = Carbon::now(); $intwo = $now->copy()->addMonths(2); $seconds = $now->diffInSeconds($intwo);
use Time::Piece; use Time::Seconds; my $now = localtime; my $intwo = $now + 2 * ONE_MONTH; my $seconds = ($intwo - $now)->seconds;
# Dude, even: date --date='2012-01-31 09:00 next Month'If you want exact calculation, express month in x amount of seconds - a twelfth of a year. Anything else is up to you to define and with it the difficulty in doing calculations with that stuff.
So? It's precise and consistent. You could then go and say: Two months from now is the same time of day as it is now on the day that contains the point in time, that is two precise months from now.'O' => 2629743, # 30.44 days (real month, but hours shift) @Your suggestion
IIRC the offical rendering of the 2 month (tm) trademark indicated a period that can be any length of time, but most likely at least two months. So in that sense, all of the code snippets in this thread have been equally validi love the ambiguity of "2 Months" trade mark.....
however has it ever been established the the aforesaid mentioned 2 months are indeed actually consecutive? which then opens another can of worms in such that are they indeed from the same Annual period?