?
Solved

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

Posted on 2007-11-22
2
Medium Priority
?
548 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

752 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