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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get dates of week, weeks starts on monday.

Status
Not open for further replies.

r2d22y

Technical User
Nov 30, 2004
46
SE
Hello

I need some help with getting dates of a specifik week, and mondays should be the first day of week. I have tried to modify existing syntax (that I have found in this forum) but the date spans dont get correct when there is a mont h shift....so can anyone help me please.

Regards/D_S
 
This the sort of thing you are after?

Code:
use Date::Calc qw(Monday_of_Week);
$year="2005";
$week="9";
($year,$month,$day) = Monday_of_Week($week,$year);
print "Monday of week $week is $day $month $year\n";
 
Thanks, but I need all dates of for example "week 9". Is there a method to add dates from the Method you gave me or is there a smarter way to get all dates at onec?

Regards/D_S
 
You can get all of the dates for the week by adding days using the 'Add_Delta_Days' function as follows:

Code:
use Date::Calc qw(Monday_of_Week);
use Date::Calc qw(Add_Delta_Days);
$year="2005";
$week="9";
($year,$month,$day) = Monday_of_Week($week,$year);
print "Monday of week $week is $day $month $year\n";
$offset="6";
($year,$month,$day) = Add_Delta_Days($year,$month,$day, $offset);
print "Sunday of week $week is $day $month $year\n";

Just change the offset value to 1 for the Tuseday, 2 for the Wednesday etc.
 
wb tony, long time, no see ;-)

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks Paul but I've never been away! I check the perl forum most days (and learn lots) but there's rarely anything I can add that improves upon what the regular guys post!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top