Solved

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

Posted on 2007-11-22
2
502 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now