Get the day of the week from a year, month and day

Given a string in the form 2010-05-22, this routine returns the day of the week as a number from 0 to 6, with 0 being Sunday.
use Time::Local;

sub get_weekday
{
    my ($date) = @_;
    my ($year, $mon, $mday) = split /-/, $date;
    $mon--;
    my $time = timegm (0, 0, 0, $mday, $mon, $year);
    my @dates = gmtime ($time);
    my $wday = $dates[6];
    return $wday;
}

Copyright © Ben Bullock 2009-2017. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com). / Privacy / Disclaimer