Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: is today a friday

by izut (Chaplain)
on Mar 10, 2006 at 19:07 UTC ( [id://535785]=note: print w/replies, xml ) Need Help??


in reply to is today a friday

localtime can receive an argument, which is the number of seconds since epoch. You can get today's time with time function, and then add the time needed in seconds (i.e. tomorrow will be time() + 24 * 60 * 60 * $days, where $days will be 1, and so).

I think it's enough for starting. You can also check Date::Manip, Date::Calc and others.

Good luck!

Igor 'izut' Sutton
your code, your rules.

Replies are listed 'Best First'.
Re^2: is today a friday
by baysbenj (Initiate) on Mar 10, 2006 at 19:12 UTC
    Thanks for the start izut. Is there any way to pass in a date without having to count the number of days that have passed since epoch? is there any way to just pass in "03102006" (today's date).
      Some or all of the modules already listed do this. Core module Time::Local also does.
      use Time::Local qw( timelocal ); my $date = '10/15/2008'; my ($m, $d, $y) = split(m{/}, $date); my $time = timelocal(0, 0, 0, $d, $m-1, $y); my $dow = (localtime($time))[6]; if ($dow == 5) { print("It's Friiiiiiiiday!\n"); } elsif ($dow == 0 || $dow == 6) { print("Sweet heavenly weekend!\n"); } else { print("Get back to work, you bum!\n"); }
      Well, you could use Mktime in Date::Calc to convert your string to unix time, then pass that to another Date::Calc function... but what's the point? Just use one of Date::Calc's Day_of_Week methods and be done with it.
      ---
      It's all fine and dandy until someone has to look at the code.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2024-04-18 08:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found