Solved

PERL - How to get 1st, 2nd, 3rd etc...  Monday, Tuesday, Wednesda, etc ... date in a month

Posted on 2007-11-22
2
512 Views
Last Modified: 2013-12-25
I need to find specific dates. I will always have the Month, Year and Marker.

i.e.
September, 2008.
I need to know the 'date' of the (for example) 1st Monday or 2nd Friday or whatever. Date can be in unixtime,localtime,mysql or some format that I can manipulate. Looking for pure perl or lightweight module.
0
Comment
Question by:Bob-Villa
2 Comments
 
LVL 9

Expert Comment

by:Suhas .
ID: 20334687
for that using module Date::Simple
my $date = ymd($year, $month, $day); # for ex sep 2008 give input year = 2008 month = 9 day = 1

then,
print "Today is ";
    print(('Sun','Mon','Tues','Wednes','Thurs','Fri','Satur')
          [$date->day_of_week]);
    print "day.\n"; # you will get the 1st day of week, ex. tuesday

after that its easy for you to find the date of the 1st mon or 3rd mon etc....
little tricky... but you have to write the loops accordingly...

Hope this helps...
0
 
LVL 28

Accepted Solution

by:
FishMonger earned 500 total points
ID: 20335377
It's not  a lightweight module, but Date::Mainip would be the easiest.
http://search.cpan.org/~sbeck/Date-Manip-5.46/Manip.pod
#!/usr/bin/perl
 
use strict;
use warnings;
use Date::Manip;
 
my $date = ParseDate("2nd Thursday in September 2008");
print "$date\n";
 
print UnixDate("2nd Thursday in September 2008",
               "The date you requested is %b %e, %Y.\n");

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question