I need to find the next date of any date.
use strict;
my $entered_date="2011-11-30";
In the above code I want to find the next date of the date, which stored in $entered_date variable... Please share your solutions....
Thanks in Advance...
$bree = 361535725; # 16 Jun 1981, 4:35:25 $nat = 96201950; # 18 Jan 1973, 3:45:50 $difference = $bree - $nat; print "There were $difference seconds between Nat and Bree\n"; There were 265333775 seconds between Nat and Bree $seconds = $difference % 60; $difference = ($difference - $seconds) / 60; $minutes = $difference ...
If you want yesterday's date: use DateTime qw( ); my $yday_date = DateTime ->now( time_zone => 'local' ) ->set_time_zone('floating') ->truncate( to => 'day' ) ->subtract( days => 1 ) ->strftime('%Y-%m-%d'); For example, in New York on 2019-05-14 at 01:00:00, it would have returned 2019-05-13.
localtime() function in Perl returns the current date and time of the system, if called without passing any argument.
Perl POSIX Specifiers The formatted date and time values can be printed by using the strftime() function of PERL by using different types of specifiers preceded with the (%) sign. Two types of specifiers are used in PERL.
use Time::Piece;
use Time::Seconds;
my $date = Time::Piece->strptime($entered_date, "%Y-%m-%d");
$date += ONE_DAY;
return $date->strftime("%Y-%m-%d");
[ edit: changed %F
to %Y-%m-%d
for Wintendo compatibility. Thanks, @bvr ]
perl -MDate::Calc -E ' use Date::Calc qw(Add_Delta_Days);say join "-", Add_Delta_Days(2011,11,30,1);'
2011-12-1
In a script (not very safe)
use Date::Calc qw(Add_Delta_Days);
my $entered_date = "2011-12-31";
print join "-", Add_Delta_Days(split(/-/,$entered_date),1);'
2012-1-1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With