Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

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
 
0
ellandrd
Asked:
ellandrd
  • 6
  • 4
  • 2
2 Solutions
 
manav_mathurCommented:
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
 
manav_mathurCommented:
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
 
ellandrdAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ellandrdAuthor Commented:
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
 
inq123Commented:
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
 
inq123Commented:
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
 
ellandrdAuthor Commented:
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
 
ellandrdAuthor Commented:
ooops sorry, my mistake, feb only has 28 days...

forget that last post...

sean
0
 
ellandrdAuthor Commented:
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
 
inq123Commented:
#!/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
 
inq123Commented:
Thanks for the points! Manav really deserves more points than I do though. :)
0
 
ellandrdAuthor Commented:
fair is fair
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now