Perl_Student has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on How do you determine the day of the week based on a certain user provided date?

Replies are listed 'Best First'.
Re: How do you determine the day of the week based on a certain user provided date?
by ghettofinger (Monk) on Mar 09, 2004 at 17:04 UTC
      An aside: As a Perl hacker, don't you just love it when someone asks for something not too common, and there happens to be a module that fits there needs perfectly, as if the module was written just for them?
        I can't remember where I read it, but it has been said that if you are going to code more than three or more(?) lines to do something, there is probably a module that will do it. No matter what I am looking for, or how obscure I think my problem is, CPAN never let's me down. Ever.

        ghettofinger

Re: How do you determine the day of the week based on a certain user provided date?
by arden (Curate) on Mar 09, 2004 at 17:08 UTC
Re: How do you determine the day of the week based on a certain user provided date?
by matija (Priest) on Mar 09, 2004 at 20:20 UTC
    First of all, kick whoever provided that date in the unmentionables, and tell him or her to give you a four digit year.

    Then, provided you really, really, don't want to use a CPAN module (which is your best option), then you use Zeller's algorithm. The source I gave has source in Pascal. You'll have to convert it to Perl yourself.

Re: How do you determine the day of the week based on a certain user provided date?
by jdtoronto (Prior) on Mar 09, 2004 at 20:02 UTC
    To my asnwer to your previous question, add the following:
    print $new_time->fullday, "\n";

    jdtoronto

Re: How do you determine the day of the week based on a certain user provided date?
by zentara (Cardinal) on Mar 10, 2004 at 16:13 UTC
    Here is a well-worn snippet from Merlyn
    #!/usr/bin/perl #by Merlyn use Time::Local; my ($year, $month, $day) = qw(2004 03 10); my $gmtime = timegm(0,0,0,$day,$month-1,$year-1900); my @gmtime = gmtime($gmtime); # convert back print "day of week is $gmtime[6]\n"; # sunday = 0, saturday = 6 my ($day_of_week) = gmtime($gmtime) =~ /^(\S+)/; # fetch first word print "day of week is $day_of_week\n"; # "Sun" .. "Sat"

    I'm not really a human, but I play one on earth. flash japh