Solved

Using Perl to compare dates

Posted on 2004-03-21
2
20,793 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to dynamically set the form action using jQuery.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

729 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