in reply to Get day of week from current date

If you need the text of the day to be in a specific format/case, you can still use localtime, and redefine the format using a hash:

#!/usr/bin/perl use strict; my @date = split(" ", localtime(time)); my $day = $date[0]; my %days = (); %days = ("Mon", "Monday", "Tue", "Tuesday", "Wed", "Wednesday", "Thur" +, "Thursday", "Fri", "Friday", "Sat", "Saturday", "Sun", "Sunday"); print STDERR "Today is $days{$day}\n";

Replies are listed 'Best First'.
Re^2: Get day of week from current date
by rjt (Curate) on Jul 09, 2013 at 00:53 UTC

    If you want to do it that way, use localtime's list context. You can avoid the string parsing which could change with locale1:

    my @wday = qw/Monday Tuesday Wednesday Thursday Friday Saturday Sunday +/; printf "Today is %s.\n", $wday[ (localtime(time))[6] - 1 ];

    See localtime for details on the returned list.


    Update: A little lot more feedback.

    _______________
    1. Whoops. localtime: The format of this scalar value is not locale-dependent but built into Perl.

      Thanks rjt!

      Michael
Re^2: Get day of week from current date
by gavrilo (Initiate) on Jul 09, 2013 at 07:01 UTC
    You Sir are a star and the good news is I even understand what you are doing :-) Thanks to everyone for the legup. Gavrilo