...

View Full Version : monday tuesday ???



ynotlim
10-12-2006, 09:52 PM
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

FishMonger
10-12-2006, 10:42 PM
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

KevinADC
10-12-2006, 10:45 PM
piece of cake: ;)



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:


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.

ynotlim
10-13-2006, 12:18 AM
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

FishMonger
10-13-2006, 12:31 AM
change
$mday-1,

to
$mday,

FishMonger
10-13-2006, 12:33 AM
Or change the array

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

KevinADC
10-13-2006, 12:39 AM
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:


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



Thanks Fish, good catch! :thumbsup:

ynotlim
10-13-2006, 01:19 AM
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??

ynotlim
10-13-2006, 01:23 AM
nevermind... got it
thanks guys

KevinADC
10-13-2006, 06:00 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum