kathys39 has asked for the wisdom of the Perl Monks concerning the following question:

I've got a short script that allows a user to enter a date. I want to convert this date to *something* so I can compare it to mtimes of a bunch of files. If the mtime of the file is within 7 days of the user-entered date, I'll do some processing. What I can't figure out is how to convert a user-entered date into the same format as mtime, so I can compare the two. Can anyone point me in the right direction?
  • Comment on convert user-entered date to compare with mtime

Replies are listed 'Best First'.
Re: convert user-entered date to compare with mtime
by moritz (Cardinal) on Oct 31, 2007 at 14:31 UTC
    This something is called "unix timestamp", and is the number of seconds since start of the epoch (whatever that means, I always forget that...)

    I'd suggest you use a module that parses the date, like Date::Parse or Date::Manip. Search on cpan for date will give you quite a list of modules.

Re: convert user-entered date to compare with mtime
by gamache (Friar) on Oct 31, 2007 at 14:32 UTC
    I think Date::Parse can help you out. Its main function is parsing human-readable dates into more machine-oriented formats.
Re: convert user-entered date to compare with mtime
by ww (Archbishop) on Oct 31, 2007 at 20:10 UTC
    And, though this may already be obvious to you, you'll have to make sure the date entered by the user is in some recognizable format...
    yyyy-mm-dd, mm/dd/yy, dd/mm/yy and so on are just a few of the variants which are widely used.
    So... you need to constrain the user's input. Guessing (perhaps utterly wrongly, but the principal applies generally) that the user entered date may be coming from a form on the web, make sure your form requires a format which one of the suggestions above can recognize.