Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How to calculate if today is before May 1

by johngg (Canon)
on Dec 29, 2019 at 15:34 UTC ( #11110728=note: print w/replies, xml ) Need Help??


in reply to How to calculate if today is before May 1

You could use the Time::Piece module which has been in the core Perl distribution since 5.10 I believe.

johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -MTime::Piece -E +' my $now = localtime(); my $may = Time::Piece->strptime( qq{@{ [ $now->year() ] }/05/01 00:00: +00}, q{%Y/%m/%d %T} ); say $now->epoch() < $may->epoch() ? q{Before 1st May} : q{After 1st May};' After 1st May

I hope this is helpful.

Update:The "false" part of the ternary would more accurately say "On or after 1st May" being pedantic.

Cheers,

JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11110728]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2020-05-27 23:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (162 votes). Check out past polls.

    Notices?