
Discussion BoardsOpen MenuDiscussion Boards Open Menu
 Welcome to the Community
 1 categories, 7 boards
 Live with HP Experts
 1 boards
 Converged Systems
 1 categories, 1 boards
 Desktops and Workstations
 1 categories, 12 boards
 Mobile
 7 boards
 Networking
 6 categories, 22 boards
 Operating Systems
 7 categories, 77 boards
 Printing and Digital Imaging
 1 categories, 18 boards

BlogsOpen MenuBlogs Open Menu

Community Knowledge BaseOpen MenuCommunity Knowledge Base Open Menu

EnglishOpen Menu
 Community Home
 >
 Operating Systems
 >
 HPUX
 >
 Languages and Scripting
 >
 Re: How to count the number of Mondays, Tuesdays e...
 Subscribe
 Mark Topic as New
 Mark Topic as Read
 Float this Topic to the Top
 Bookmark
 Subscribe
 Printer Friendly Page
How to count the number of Mondays, Tuesdays etc between two given dates ?
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
09132006 08:54 PM
Please tell me .
Solved! Go to Solution.
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
09132006 08:58 PM
Search forums for caljd.sh
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
09132006 09:02 PM
search inside this thread for the word caljd.
http://forums1.itrc.hp.com/service/forums/question
latest version of this script can be downloaded from.
http://mirrors.develooper.com/hpux/index.html#Cont
Regards,
RobertJan
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
09132006 09:07 PM
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
09132006 09:09 PM
http://mirrors.develooper.com/hpux/caljd2.2.pl
regards,
RobertJan
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
09132006 09:16 PM
can i have a small script which I can insert into my perl cgi program ?
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
09132006 09:33 PM
once you have the script:
1. strip out the '' out of the date
2. convert the start date to Julian with 'y' option.
3. Same for end date
4. run a loop while start date < end date
5. use w to get the weekday
6. case statement to add 1 to the Mon,Tue,Wed... array
7. end of loop
8. Print out your array
Bourne version of this attached
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
09132006 11:47 PM
One way is to use Perl's Date::Calc module. You can verify your dates (if necessary) with its 'check_date' function and determine the difference between a set of dates with its 'Delta_Days' function.
If you want to rollyouown, you can use the Time::Local module; regular expressions or unpack() to parse your dates; convert to epoch secnods and determine the delta value in days.
Once you have the number of days, inclusive or exclusive of the range points, a "div 7" will give you the number of Mondays, Tuesdays or whatever represented the day associated with the beginning date.
Regards!
...JRF...
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
09142006 02:18 AM
The reason that this script is so large is primarily argument parsing and usage and examples but also providing NLS support adds to the complexity but in any event the subroutines that you need are very small.
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
09142006 02:22 AM
log of my earlier post:
$ ./x.sh "20060914" "20060922"
Start Julian: 2453993
End Julian: 2454001
Mondays : 1
Tuesdays : 1
Wednesdays : 1
Thursdays : 2
Fridays : 1
Saturdays : 1
Sundays : 1
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
09142006 07:01 AM
Modified it to do the bruteforce count, like Peter did.
It should basically be a simple divide by 7 of end day minus begin day but taking the begin and end dayofthe week into account made my head hurt.
Note, there is one gotcha if you play with timelocal local. You can get a surpise 3600 seconds difference on the right/wrong days.
In 2006 in the EDT zone 0h0 4/2  0h0 43 = 82800 seconds 0.958333333333333 days, not 86400 and 1.
Rounding takes care of that as needed.
Bruteforce perl:
use Time::Local;
sub mytime {
my ($y,$m,$d) = split //,$_[0];
return timelocal(0,0,0,$d,$m1,$y);
}
$beg = mytime(shift @ARGV);
$end = mytime(shift @ARGV);
@nam = qw/Sun Mon Tue Wed Thu Fri Sat/;
for $i (0..6) { $weeks[$i]=0 }
# barely tolerant for daylight saving jumps
for ($i=$beg; $i < $end; $i += 86400) {
$weeks[(localtime($i))[6]]++;
}
for $i (0..6) {
print "$nam[$i] $weeks[$i]\n";
}
Cheers,
Hein.
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
09182006 11:24 PM
Also I took care of the remainder by the modulus(%) operator to calculate the exact no. of Mondays, Tuesdays etc.
I have given you all points.
Thanks a lot to all of you.