Paul Kraus wrote:
>
> How can I convert a date that is a string such as "12/12/03" to apoch so
> that I can then compare it to time and if its <= time do something.
> I can't give code because this is still a concept.
>
> But the check is that cron will scan a directory hourly or daily. Parse
> the filenames which are going to be formatted vendorcode-date.csv
> If date <= to current date then call a script that runs an update
> against some proprietary accounting software that we have.

Hi Paul.

I would go for Date::Simple.

Your date is one of the classic Y2K and mm/dd ambiguities, so
I'll assume you're using the US mm/dd/yy format and just add
2000 to the year. I've also changed 'dd' to 25 so that it can't
be a month.

Take a look at the program below. The Constructor
takes either a 'yyyy-mm-dd' string or ($yyyy, $mm, $dd)
parameters. Once you have Date::Simple objects you can compare
them, subtract them (for a delta time) or do arithmetic
on them (like $simple += 7 is the same day next week.)

HTH,

Rob



use strict;
use warnings;

use Date::Simple;

my $date = "12/25/03";

my @mdy = split /\//, $date;
$mdy[2] += 2000;                            # Turn year into 2003

my $simple = new Date::Simple @mdy[2,0,1];  # Change @mdy into ($y, $m, $d)

my $today = new Date::Simple;               # No params means 'now'.

if ($simple > $today) {
  print "Soon!\n";
}
else {
  print "Missed it!!\n";
}



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to