Web Analytics Made Easy -
StatCounter monday tuesday ??? - CodingForum

Announcement

Collapse
No announcement yet.

monday tuesday ???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • monday tuesday ???

    Hello...

    is there any script or function I can use to figure out if a date is on M/T/W/T/F/S/S ???

    IE.
    $mm_dd_yy= 04-21-83;
    $day_ofthe_week = xfunction($mm_dd_yy)

    Thank you in advance...

    Tony
    ---------
    Client / Server Side Programmer II

  • #2
    Look at the Date::Calc module

    Day_of_Week()
    and
    Day_of_Week_to_Text()

    http://search.cpan.org/~stbey/Date-Calc-5.4/Calc.pod

    Comment


    • #3
      piece of cake:

      Code:
      use Time::Local 'timelocal_nocheck';
      my @weekday = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
      my $mm_dd_yy = '04-21-83';
      my ($mon,$mday,$year) = $mm_dd_yy =~ /(\d+)-(\d+)-(\d+)/;
      my $epochtime = timelocal_nocheck(0,0,0,
                                        $mday-1,
                                        $mon-1,
                                        $year
                                       );
      my $day = (localtime($epochtime))[6];
      print $weekday[$day];
      or less readably:

      Code:
      use Time::Local 'timelocal_nocheck';
      my @weekday = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
      my $mm_dd_yy = '04-21-83';
      my ($mon,$mday,$year) = $mm_dd_yy =~ /(\d+)-(\d+)-(\d+)/;
      print $weekday[(localtime(timelocal_nocheck(0,0,0,$mday-1,$mon-1,$year)))[6]];
      You can use one of the Date modules too but they would most likely need to be installed on the server/computer. The above code works with just core functions and modules.

      Comment


      • #4
        hi Kevin,

        You are right, i don't have that script installed on my server. And I'm not the admin, so I can't install it either. Your thing on the other hand is giving me the wrong days of the week. Am I doing something wrong? I double checked your code, and i think the $mday is the nth day of the year stated.

        what do you think?

        Tony
        ---------
        Client / Server Side Programmer II

        Comment


        • #5
          change
          $mday-1,

          to
          $mday,

          Comment


          • #6
            Or change the array

            my @weekday = qw(Monday Tuesday Wednesday Thursday Friday Saturday Sunday);

            Comment


            • #7
              Originally posted by FishMonger View Post
              change
              $mday-1,

              to
              $mday,
              Not sure how I added the -1 to $mday, I pulled that code right out of a script I wrote a while back and it's not in my original code:

              Code:
                 my $epochtime = timelocal_nocheck(0,0,0,
                                                   $mday,
                                                   $mon-1,
                                                   $year
                                                  );


              Thanks Fish, good catch!
              Last edited by KevinADC; Oct 12, 2006, 08:41 PM.

              Comment


              • #8
                sorry guys... it still isn't working out right. I've tried rearranging the days, taking out he -1's etc. And when i test it w/ random days and years, it is giving me the wrong days of the week. Sometimes it will work for a particular month, but not when I change the month.

                are you having the same problem??
                ---------
                Client / Server Side Programmer II

                Comment


                • #9
                  nevermind... got it
                  thanks guys
                  ---------
                  Client / Server Side Programmer II

                  Comment


                  • #10
                    Originally posted by ynotlim View Post
                    sorry guys... it still isn't working out right. I've tried rearranging the days, taking out he -1's etc. And when i test it w/ random days and years, it is giving me the wrong days of the week. Sometimes it will work for a particular month, but not when I change the month.

                    are you having the same problem??
                    worked fine for me. Thats code I pulled out of an old script I wrote and it always returned the correct day of the week when used properly.

                    Comment

                    Working...
                    X