Link to home
Start Free TrialLog in
Avatar of ellandrd
ellandrdFlag for Ireland

asked on

comparing system date and date value got from a db

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
 
Avatar of manav_mathur
manav_mathur

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
ASKER CERTIFIED SOLUTION
Avatar of manav_mathur
manav_mathur

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ellandrd

ASKER

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...
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...
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";
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
ooops sorry, my mistake, feb only has 28 days...

forget that last post...

sean
my other question still requires help as i have errors in code:

look here:

https://www.experts-exchange.com/questions/21331661/PERL-ODBC-translate-php-odbc-page-into-a-perl-odbc-page.html
#!/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;
Thanks for the points! Manav really deserves more points than I do though. :)
fair is fair