- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- How to count the number of Mondays, Tuesdays etc b...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2006 08:54 PM
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2006 08:58 PM
09-13-2006 08:58 PM
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
Search forums for caljd.sh
- Tags:
- caljd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2006 09:02 PM
09-13-2006 09:02 PM
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
search inside this thread for the word caljd.
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=123030
latest version of this script can be downloaded from.
http://mirrors.develooper.com/hpux/index.html#Contrib
Regards,
Robert-Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2006 09:07 PM
09-13-2006 09:07 PM
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2006 09:09 PM
09-13-2006 09:09 PM
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
http://mirrors.develooper.com/hpux/caljd-2.2.pl
regards,
Robert-Jan
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2006 09:16 PM
09-13-2006 09:16 PM
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
can i have a small script which I can insert into my perl cgi program ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2006 09:33 PM
09-13-2006 09:33 PM
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
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
- Tags:
- missing attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2006 11:47 PM
09-13-2006 11:47 PM
SolutionOne 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 roll-you-own, 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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2006 02:18 AM
09-14-2006 02:18 AM
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2006 02:22 AM
09-14-2006 02:22 AM
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
log of my earlier post:
$ ./x.sh "2006-09-14" "2006-09-22"
Start Julian: 2453993
End Julian: 2454001
Mondays : 1
Tuesdays : 1
Wednesdays : 1
Thursdays : 2
Fridays : 1
Saturdays : 1
Sundays : 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2006 07:01 AM
09-14-2006 07:01 AM
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
Modified it to do the brute-force 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 day-of-the 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 4-3 = 82800 seconds 0.958333333333333 days, not 86400 and 1.
Rounding takes care of that as needed.
Brute-force perl:
use Time::Local;
sub mytime {
my ($y,$m,$d) = split /-/,$_[0];
return timelocal(0,0,0,$d,$m-1,$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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2006 11:24 PM
09-18-2006 11:24 PM
Re: How to count the number of Mondays, Tuesdays etc between two given dates ?
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.