Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Answer: 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 ( #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? - Answer 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
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
Chatterbox?
[Corion]: Hehe - $work is a place where we have lots of (money) accounts, and lots of journals where every transaction is recorded. But our HR system where the accounts of hours worked and vacation days taken are stored, there is no real account of who changed ...
[Corion]: ... that balance, and when. And it seems to me that they somehow really messed up the database since the start of the year and have been frantically adding and subtracting numbers from the totals, but without trace ;)

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2018-01-23 16:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (248 votes). Check out past polls.

    Notices?