testing or detecting valid "date" data type

J

Jack

Hi folks,

I am looking to find some code that tests a string as being a valid
"date" data type.. I tried this but it doesnt seem to work

$ENV{TZ} = 'PST';
use Date::Manip;
$datetest = '1111';
$date = ParseDate($datetest);
print $date;

This program returns: 1111010100:00:00
which is not a valid date for example, obviously.

Any help would be appreciated
 
P

Paul Lalli

Jack said:
I am looking to find some code that tests a string as being a valid
"date" data type.. I tried this but it doesnt seem to work

It *works* exactly as it's supposed to. It just doesn't do what you
*want* it to do.
$ENV{TZ} = 'PST';
use Date::Manip;
$datetest = '1111';
$date = ParseDate($datetest);
print $date;

This program returns: 1111010100:00:00
which is not a valid date for example, obviously.

You have a different definition of "obviously" than I do. That is the
date January 1, 1111, at 12:00:00am. That is what happens when you
pass only a year to ParseDate. If you'd read the documentation for the
module you're using, you'd probably have found that a four-digit year
is an acceptable argument to ParseDate.

I don't think Date::Manip is the module you should be using. Instead,
figure out what your possible date formats are, and then use a module
such as Regexp::Common::time
http://search.cpan.org/~roode/Regexp-Common-time-0.01/time.pm

Paul Lalli
 
B

Ben Morrow

Quoth "Jack said:
Hi folks,

I am looking to find some code that tests a string as being a valid
"date" data type.. I tried this but it doesnt seem to work

$ENV{TZ} = 'PST';
use Date::Manip;
$datetest = '1111';
$date = ParseDate($datetest);
print $date;

This program returns: 1111010100:00:00
which is not a valid date for example, obviously.

What makes you think that? It's midnight on the first of January
AD 1111. A perfectly sensible date, though maybe not what you meant.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,635
Latest member
SkyePurves

Latest Threads

Top