Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by poolpi (Hermit)
on Feb 06, 2009 at 10:47 UTC ( [id://741862]=note: print w/replies, xml ) Need Help??


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

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 Re: How to get time in seconds from localtime(time) to next 21st date of the month?
  • Download Code

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://741862]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found