Solved

Using Perl to compare dates

Posted on 2004-03-21
2
20,764 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
ID: 10646136
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
ID: 10652817
could you please post the assignemts to these variables
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
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 …
The viewer will learn how to dynamically set the form action using jQuery.

776 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