On Fri, 6 Mar 2009 14:42:48 -0800 (PST)
Bobby <cybercruis...@yahoo.com> wrote:

> 
> Hi, 
> 
> Could someone take a look at the code for me below and see if you can
> figure out what's wrong with it? I just want to evaluate
> $publish_date to see if it's with 21 days of the current date; if so
> then set $new_item=" True". Not sure why it's not doing that, I think
> the it's not evaluating the if statement. I do have Date::CalC
> installed. Thanks.  
> 
> "if (my ($year1,$month1,$day1) = Decode_Date_US($mmddyyy))". 
> 
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> sub NewProducts
>   {
> 
>  use Time::localtime;
>  use Time::Local;
>  use Date::Calc qw(:all);
> 
>   # Create date property in format mmddyyyy
>   # for input to Decode_Date_US() function below
>   my $publish_date = "01/02/2009 12:32:03 PM";
>   my $mmddyyyy = substr($publish_date, 5, 2);
>   $mmddyyyy .= substr($publish_date, 8, 2);
>   $mmddyyyy .= substr($publish_date, 0, 4);
>         if (my ($year1,$month1,$day1) = Decode_Date_US($mmddyyyy))
>                 {
>                 my ($year2,$month2,$day2) = Today();
>                 my $delta = Delta_Days($year1, $month1, $day1,
> $year2, $month2, $day2); if($delta <= 21 && $delta >= 0)
> 
>                         {
>                           my $new_item = "True";
>                           
>                         }
>                 
>                 }
>    
>   } #End of sub
> 
> &NewProducts();
> 


I am not sure what you expected, but here is a rewrite which you could
look at and see how it works.


Owen

=========================================================

#!/usr/bin/perl
use strict;
use warnings;

use Time::Local;
use Date::Calc qw(:all); # no need to use all, just Delta_Days

my ( $year2, $month2, $day2 ) = Today();

my $publish_date = "03/02/2009 12:32:03 PM"; # Be sure of this format

my ( $mm, $j1, $dd, $j2, $yyyy ) = unpack( "A2 A1 A2 A1 A4",
$publish_date );

print "$yyyy $mm $dd\t\t$year2 $month2 $day2\n";

my $delta = Delta_Days( $year2, $month2, $day2, $yyyy, $mm, $dd );
print "$delta\n";


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to