Solved

Using Perl to compare dates

Posted on 2004-03-21
2
20,756 Views
Last Modified: 2013-12-25
I have created a grade book for myself to record my student's math grades. I want to compare the date that I gave the assignment with the quarter's beginning and ending date to show all grades for a given quarter.
...
if ( $assgndate >= $begdate && $assigndate <= $enddate).....

I have used Date::Manip to assist me with the comparison but when I few the error logs
I get error the following type of messages:

[ERROR]{ARGUMENT 20043xxxx is numeric in ge ( >=)...
I also get the same reply for the <= comparison, too

The script does work. I was just curious is there a better, hopefully easier, way to compare dates?

0
Comment
Question by:lynn402
2 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 125 total points
Comment Utility
If you are using ISO date formats, then you don't need a big, clumsy module like Date::Manip (unless you are doing other complicated date comparisons)

So if you have:

$assigndate=20040301;
$begdate=20040101;
$enddate=20041201;

Then doing

if ($assigndate >= $begdate and $assigndate <= $enddate) {
    print "$assigndate is within the begin and end dates\n";
}

The error message you mention (although you missed a *very* important word, ie: "is" should be "isn't") is caused by one of the variables being non-numeric.

For example:

$ cat date
$a=20040101;
print if ($a >= 'a');

$ perl -w date
Argument "a" isn't numeric in numeric ge (>=) at date line 2.
Use of uninitialized value in print at date line 2.
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
could you please post the assignemts to these variables
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
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…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 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

10 Experts available now in Live!

Get 1:1 Help Now