Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

howto list all 2008 fridays mm/dd/yyyy 1

Status
Not open for further replies.

Stumpr

Technical User
Jan 2, 2004
1,178
0
0
US
How can I get a list of dates for all Fridays in 2008 in MM/DD/YYYY format?
how about all Saturdays?
or all Sundays?



Bob Stump
VERITAS - "Ain't it the truth?"
 
Try this:

Code:
#!/usr/bin/perl

use POSIX;

$targetyear=2008-1900;
$targetday=5; # Friday

# Find first $targetday of the year
for ($mday=1; $mday<=7 && $wday !=$targetday; $mday++) {
        $time_t = POSIX::mktime( 0, 0, 0, $mday, 0, $targetyear );
        (undef,undef,undef,undef,undef,$year,$wday,$yday,undef) = localtime($time_t);
}

# Print date every 7 days until end of the year
do  {
        print strftime "%m/%d/%Y\n",localtime $time_t;
        $time_t = POSIX::mktime( 0, 0, 0, $mday+7, $mon, $year );
        (undef,undef,undef,$mday,$mon,$year,undef,undef,undef) = localtime($time_t);
} until ($year != $targetyear)

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top