Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

regular expression for vb date format

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I'm new to Regular Expression
I need the regular expression for the following date format.
mm/dd/yyyy hh:mm:ss AM
eg:
1/1/2008 5:06:09 PM
12/25/2003 12:24:30 AM

for date ,month and hour there will not be leading '0' and for minutes ,sec there will leading '0'.


Thanks in Advance
Suresh babu A
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The time is not hard to do for a reg exp, but the date is because of leap year, months with 28, 30,21 days.

There are example out there on the net to solve that, but it is an ugly string.

The best solution if you can do it is to use that string and feed it into a new Date object. That take the date string and split it apart and compare that against the Date.

AT that point you can also run simple reg exs against the string to see it is in the right format.

Eric
 
A j Suresh babu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi eric,
Thank you for Your reply .
I'm doing J2ee application but i will get the request object from the asp page .In the request paramater i will get the string like
"CookieToken=1/1/2008 5:06:09 PM; UNTOPRX=GGSDFGVXGSCRWGJHDXGSGGDGFSWDHGSDGH="
so in my java script i want to replace the date with another date.
so i will be using the Sting.replace methos in javascript.
In string.replace the first argument is the regular expression.
so i need the regular expression for the following date format.
The Date may be in following format.
mm/dd/yyyy hh:mm:ss AM
eg:
1/1/2008 5:06:09 PM
12/25/2003 12:24:30 AM

for month,day and hour there will not be leading '0' and for minutes ,sec there will leading '0'.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you really do not need to match the date format than. You can basically do:



Eric
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also please do not email me your question. I will see your question and response here. Emailing me is just wasting your time.

Eric
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic