Solved

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

Posted on 2004-09-26
8
220 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

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
 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Check if a filw is immutable for a certain amount of time 6 64
linux redhat 7.2 10 74
android secure ftp 3 38
bash file 10 37
This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

832 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