?
Solved

comparing system date and date value got from a db

Posted on 2005-02-28
12
Medium Priority
?
407 Views
Last Modified: 2010-05-18
i read into perl variables from a db 2 date values

1) system date -> 28/02/2005
2) deadline date -> 25/05/2005

what i need is to compare these 2 dates and output the number of days left to the deadline date...

but, but if the deadline date is after the system date,
output "document overdue"

else if the deadline date is same as system date,
output "0 days remaining"

else if deadline date is greater than system date,
output the number of days remaining...

i require all this to be acheived in perl...

thanks sean
 
0
Comment
Question by:ellandrd
[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
  • 6
  • 4
  • 2
12 Comments
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13421660
use Date::Calc qw(Date_to_Days) ;
my $sysdate = "28/02/2005"
my $deaddate = "25/05/2005"
my $source_days = Date_to_Days ((split(/\//,$sysdate)[2],(split(/\//,$sysdate)[1],(split(/\//,$sysdate)[0]) ;
my $dead_days = Date_to_Days ((split(/\//,$deaddate)[2],(split(/\//,$deaddate)[1],(split(/\//,$deaddate)[0]) ;
if ($source_days > $dead_days) {print "Document Overdue.."} else {print $dead_days-$source_days,"days remaining"}


Manav
0
 
LVL 16

Accepted Solution

by:
manav_mathur earned 1000 total points
ID: 13421942
use Date::Calc qw(Date_to_Days) ;
my $sysdate = "28/02/2005"
my $deaddate = "25/05/2005"
my $source_days = Date_to_Days ((split(/\//,$sysdate)[2,1,0]) ;
my $dead_days = Date_to_Days ((split(/\//,$deaddate)[2,1,0]) ;
if ($source_days > $dead_days) {print "Document Overdue.."} else {print $dead_days-$source_days,"days remaining"}


...should work too.

Manav
0
 
LVL 16

Author Comment

by:ellandrd
ID: 13422589
errors:

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


syntax error at C:\Documents and Settings\Sean Delaney\My Documents\Testing Folder\perl\dates2.pl line 3, near "my "
syntax error at C:\Documents and Settings\Sean Delaney\My Documents\Testing Folder\perl\dates2.pl line 5, near ")["
Execution of C:\Documents and Settings\Sean Delaney

same error for both...

i ahve got date-calc.ppd installed...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Author Comment

by:ellandrd
ID: 13423067
ellandrd,
 please full perl code so i only have to copy and paste into date.pl and run it, getting it to work first time...
0
 
LVL 8

Expert Comment

by:inq123
ID: 13423211
the error message you got was because there was no ';' at the end of the two lines: just change

my $sysdate = "28/02/2005"
my $deaddate = "25/05/2005"

to

my $sysdate = "28/02/2005";
my $deaddate = "25/05/2005";
0
 
LVL 8

Assisted Solution

by:inq123
inq123 earned 1000 total points
ID: 13423251
manav's code is basically working, except that a couple ';' and ')' were missed.  Here's the modified version of manav's code that you can copy and paste:

use Date::Calc qw(Date_to_Days);
my $sysdate = "28/02/2005";
my $deaddate = "25/05/2005";
my $source_days = Date_to_Days ((split(/\//,$sysdate))[2,1,0]);
my $dead_days = Date_to_Days ((split(/\//,$deaddate))[2,1,0]);
if ($source_days > $dead_days) {print "Document Overdue.."}
else {print $dead_days-$source_days,"days remaining"}
0
 
LVL 16

Author Comment

by:ellandrd
ID: 13423554
one little error,

the 3 main function is:

if system date is greater than deadline date output "document overdue"
if system date is less than deadline date output "number of days left to deadline"
if system date is equal to deadline date output "deadline is today"

the above code works for

my $sysdate = "28/02/2005";
my $deaddate = "25/02/2005"; <<<< which returns "document overdue"

my $sysdate = "28/02/2005";
my $deaddate = 25"/03/2005"; <<<< which return "number of days left"

but if i use dates that are 1 days in different like

my $sysdate = "28/02/2005";
my $deaddate = "29/02/2005"; <<<<< which returns nothing??

here is my code that i used:

#!/usr/bin/perl

use CGI ':standard';
use Date::Calc qw(Date_to_Days);

print header,start_html();

my $sysdate = "28/02/2005";
my $deaddate = "29/02/2005";
my $source_days = Date_to_Days ((split(/\//,$sysdate))[2,1,0]);
my $dead_days = Date_to_Days ((split(/\//,$deaddate))[2,1,0]);
if ($source_days > $dead_days)
{
       print "Document Overdue.."
}
else
{
       print $dead_days-$source_days,"days remaining"
}

print end_html;
 
i hope we can get this working like i asked for above...

sean
0
 
LVL 16

Author Comment

by:ellandrd
ID: 13423571
ooops sorry, my mistake, feb only has 28 days...

forget that last post...

sean
0
 
LVL 16

Author Comment

by:ellandrd
ID: 13423607
my other question still requires help as i have errors in code:

look here:

http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_21331661.html
0
 
LVL 8

Expert Comment

by:inq123
ID: 13423612
#!/usr/bin/perl

use CGI ':standard';
use Date::Calc qw(Date_to_Days);

print header,start_html();

my $sysdate = "28/02/2005";
my $deaddate = "28/01/2005";
my $source_days = Date_to_Days ((split(/\//,$sysdate))[2,1,0]);
my $dead_days = Date_to_Days ((split(/\//,$deaddate))[2,1,0]);
if ($source_days > $dead_days)
{
  print "Document Overdue.."
}
elsif($source_days == $dead_days)
{
  print "deadline is today"
}
else
{
  print $dead_days-$source_days,"days remaining"
}

print end_html;
0
 
LVL 8

Expert Comment

by:inq123
ID: 13423644
Thanks for the points! Manav really deserves more points than I do though. :)
0
 
LVL 16

Author Comment

by:ellandrd
ID: 13424129
fair is fair
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

764 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