Solved

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

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 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

18 Experts available now in Live!

Get 1:1 Help Now