Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Answer: How to get time in seconds from localtime(time) to next 21st date of the month?

( #741862=categorized answer: print w/ replies, xml ) Need Help??

Q&A > dates and times > How to get time in seconds from localtime(time) to next 21st date of the month? contributed by poolpi

POSIX example

#!/usr/bin/perl use strict; use warnings; use POSIX (); my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = POSIX::localtime(time); print POSIX::difftime( POSIX::mktime( 0, 0, 12, 21, ( $mday >= 21 ? ( ( $mon + 1 ) % 11 ) : $mon ), ( ( $mon == 11 and $mday >= 21 ) ? $year + 1 : $year ) ), POSIX::mktime( $sec, $min, $hour, $mday, $mon, $year ) ), "\n";

Comment on Answer: How to get time in seconds from localtime(time) to next 21st date of the month?
Download Code
Re: Answer: How to get time in seconds from localtime(time) to next 21st date of the month?
by doug (Pilgrim) on Feb 06, 2009 at 18:00 UTC
    #!/usr/bin/perl

    use strict;
    use warnings;

    use Date::Manip;

    my $now = ParseDate 'now';
    my $then = ParseDate 'next month';
    substr($then,6,2) = 21;
    my $delta = DateCalc $now, $then;
    my $seconds = Delta_Format $delta, 0, '%sh';
    print "seconds=$seconds days=", $seconds/(60*60*24), "\n";

    Directly hacking the Date::Manip date format to stick a 21 in the day field is ugly, but couldn't remember how to do it with the API.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2015-07-06 23:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (85 votes), past polls