Solved

Program Won't Record Dates Such as 9/23/2004

Posted on 2004-09-26
8
218 Views
Last Modified: 2010-04-20
I Have this typed in my perl code:
use CGI qq(:standard escapeHTML);

if ($date=~ /\d\d?[-/]/d/d?[-/]\d\d\d\d/){
do this......
this......
and this.....
}

It works when I have 9-23-2004 but not when I have 9/23/2004

I have a subroutine that changes the date to a format mysql understands. 2004-09-22

I have tried escaping / with \/ but it still doesn''work
0
Comment
Question by:lynn402
  • 3
  • 3
  • 2
8 Comments
 
LVL 40

Expert Comment

by:jlevie
ID: 12156476
Try "if($date =~ /\d\d-\d\d-\d\d\d\d/ || $date =~ /\d\d\/\d\d\/\d\d\d\d/)"
0
 
LVL 4

Expert Comment

by:EinarTh
ID: 12159288
Correct expression is:

/\d\d?[-\/]\d\d?[-\/]\d\d\d\d/

cheers.
0
 
LVL 4

Expert Comment

by:EinarTh
ID: 12159297
or even:

/(\d{1,2}[-\/]){2}\d{4}/

cheers
0
 

Author Comment

by:lynn402
ID: 12175559
It still doesn't work, EinarTh, I've tried \d\d?[-\/] and it never worked. jlieve, your suggestion didn't work either.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:lynn402
ID: 12175743
I'm using Perl's CGI.pm

use CGI; qq(:starndard );
#the date is located inside  query_string
$date=query_string;


print $date
#before the if statement executed I printed $date and got when the date was 9/28/2004
9%2F18%2F2004
#How can I  change the hex info back to the / so it will get recognized

if ($date=~ /\d\d?[-/]/d/d?[-/]\d\d\d\d/){
do this......
this......
and this.....
}
0
 
LVL 40

Expert Comment

by:jlevie
ID: 12175813
Oops, I just realized that my comment wasn't exactly right for the data you show in the question. It should have been:

if($date =~ /\d{1,2}-\d{1,2}-\d{2,4}/ || $date =~ /\d{1,2}\/\d{1,2}\/\d{2,4}/)

I was looking at the SQL date representation which uses 2 digit month & day and 4 digit years. The if statement above is correct in the general case as shown by:

#!/usr/bin/perl
$date[0] = "9-27-2004";
$date[1] = "09-27-04";
$date[2] = "9/28/2004";
$date[3] = "09/1/04";

for($i=0; $i<=3; $i++)
{
  $date = $date[$i];
  if($date =~ /\d{1,2}-\d{1,2}-\d{2,4}/ || $date =~ /\d{1,2}\/\d{1,2}\/\d{2,4}/)
  {
    print "Date ($date) valid\n";
  }
  else
  {
    print "Date ($date) invalid\n";
  }
}

chaos> perl dates-check
Date (9-27-2004) valid
Date (09-27-04) valid
Date (9/28/2004) valid
Date (09/1/04) valid
0
 
LVL 40

Expert Comment

by:jlevie
ID: 12175826
> 9%2F18%2F2004
> #How can I  change the hex info back to the / so it will get recognized

$date =~ s/%2F/\//g;
0
 
LVL 4

Accepted Solution

by:
EinarTh earned 50 total points
ID: 12181223
Sorry, didn't notice you url-encoded the dates.

There is a cgi function to url-decode it, but I dont have perl in front of me right now.

In any case you can:

$date =~ s/%2F/\//gi;

and then use the expression in the previous comment.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now