I have a small CGI script that accepts dates from users and lets them do a database lookup. This script has been working for years with minor changes. The last time I changed the script was to upgrade the server to Debian Squeeze, where there were some minor syntax changes.

However in the last month or so, the date search function stopped working. Many people had the dates default to the current day, regardless of what they entered into the CGI. Testing revealed that the date function worked fine, as long as proper syntax was used. But I use date::manip to make it as user friendly as possible!

I've cut the troublesome part of the script out, and it is included below together with sample output.

#!/usr/bin/perl -T use strict; use Date::Manip; my $raw_date1 == $ARGV[0]; + # Default to today if date is blank: + if ( $raw_date1 == "" ) { + print "In blank date check. But is the date truly blank? It +is in fact \"$raw_date1\"\n"; + $raw_date1 = UnixDate("today","%Y-%m-%d"); }; $raw_date1 = ParseDate($raw_date1); + # fix the dates to MySQL format: + my $date1 = UnixDate($raw_date1,"%Y-%m-%d"); + print "$raw_date1 was changed to $date1\n";

sorry for the cut & paste munging.

And here is the output:

I expect this:

jfzuelow@city-liza-lnx:~$ ./odd-date.pl + In blank date check. But is the date truly blank? It is in fact "" + 2013020200:00:00 was changed to 2013-02-02

And I expect this:

jfzuelow@city-liza-lnx:~$ ./odd-date.pl "15 jan" 2013011500:00:00 was changed to 2013-01-15

However this is very confusing to me, and my users:

jfzuelow@city-liza-lnx:~$ ./odd-date.pl "jan 15" In blank date check. But is the date truly blank? It is in fact "jan + 15" 2013020200:00:00 was changed to 2013-02-02

Ideas?


In reply to date::manip question by e5z8652

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.