Compare Dates

A

amerar

Hi All,

Here is a good one: I need to compare 2 dates, without the year.
Basically I want to know if a specific calendar date falls between two
other dates. Everything is in YYYY-MO-DD, the way Perl wants it.

So, say I am looking for a birthday. I do not care about the year, I
just want to know if a birthday falls between two dates in the
calendar.......

Any suggestions? Date::Manip??? Did not seem to do what I want.

Thanks!
 
G

Gunnar Hjalmarsson

Here is a good one: I need to compare 2 dates, without the year.
Basically I want to know if a specific calendar date falls between two
other dates. Everything is in YYYY-MO-DD, the way Perl wants it.

Just strip the year:

my $day = substr $date, 5;

and do stringwise comparisons.
 
B

Ben Bullock

Here is a good one: I need to compare 2 dates, without the year.
Basically I want to know if a specific calendar date falls between two
other dates. Everything is in YYYY-MO-DD, the way Perl wants it.

So, say I am looking for a birthday. I do not care about the year, I
just want to know if a birthday falls between two dates in the
calendar.......

Any suggestions? Date::Manip??? Did not seem to do what I want.

Change the year of all your dates to be the same arbitrary year (make it a
leap year), then use the Day_of_Year function from
Date::Calc to get the day of the year (see
http://www.unix.org.ua/orelly/perl/cookbook/ch03_07.htm), then compare the
numbers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top