Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    5
    Thanked 0 Times in 0 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

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,836
    Thanks
    2
    Thanked 158 Times in 153 Posts
    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

  • #3
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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

  • #5
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,836
    Thanks
    2
    Thanked 158 Times in 153 Posts
    change
    $mday-1,

    to
    $mday,

  • #6
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,836
    Thanks
    2
    Thanked 158 Times in 153 Posts
    Or change the array

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

  • #7
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    Quote 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; 10-13-2006 at 12:41 AM.

  • #8
    Regular Coder
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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??

  • #9
    Regular Coder
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    5
    Thanked 0 Times in 0 Posts
    nevermind... got it
    thanks guys

  • #10
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    Quote 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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •