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:
# JAVA
# PHP
# PERL
Some more languages:
# JAVA
Code:
org.joda.time.Seconds.secondBetween(now, intwo)
# PHP
PHP:
use Carbon\Carbon;
$now = Carbon::now();
$intwo = $now->copy()->addMonths(2);
$seconds = $now->diffInSeconds($intwo);
# PERL
Code:
use Time::Piece;
use Time::Seconds;
my $now = localtime;
my $intwo = $now + 2 * ONE_MONTH;
my $seconds = ($intwo - $now)->seconds;
Last edited: