472,108 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,108 software developers and data experts.

Date Validation YYYY-MM-DD

16
Hi, I am new to ASP and have been using thescripts for a lot of trouble shooting.

My problem is I am trying to convert a PHP site over to ASP. I have gotten a good grasp on most things. At the current time I am still have trouble with validation in asp.

The following code is taking an input field and checking to see if it is in YYYY-MM-DD format.

I am rewritting the ASP code and trying to get the final output to DD/MM/YYYY
The current format I still want them to use to input the date with will be

YYYY-MM-DD, I can use the split and rewrite it to DD/MM/YYYY

So any help or suggestions or links to let me read and/or learn about ASP validation and to rewrite the following code to asp would help greatly.. Thanks!

[ php ]
function testDate($idate) {
$outime = '';
$idate = trim($idate);
if (ereg ("^([0-9]{4})[^0-9]([0-9]{1,2})[^0-9]([0-9]{1,2})$", $idate, $regs)) {
$dparts=array($regs[2],$regs[3],$regs[1]);
} elseif (ereg ("^([0-9]{2})([0-9]{2})([0-9]{2,4})$", $idate, $regs)) {
$dparts=array($regs[1],$regs[2],$regs[3]);
} else {
$dparts = split('[^0-9]',$idate);
}
if (checkdate($dparts[0]+0,$dparts[1]+0,$dparts[2]+0)) {
$indate = strtotime($dparts[2].'-'.$dparts[0].'-'.$dparts[1]);
$outime = date('Y-m-d', $indate);
}
return $outime;
}
[ /php ]
Jun 15 '07 #1
2 2819
improvcornartist
303 Expert 100+
This may not be the most efficient way to go about it, but it might give you a start.

Expand|Select|Wrap|Line Numbers
  1. dim mydate
  2. mydate = "2007-06-15"
  3.  
  4. Dim arr
  5. arr = Split( mydate, "-" )
  6.  
Access each array member with arr(0), arr(1), arr(2). You should be able to test on them to check if they are numbers and whether they fall in the correct range.
Jun 15 '07 #2
Bruno43
16
This may not be the most efficient way to go about it, but it might give you a start.

Expand|Select|Wrap|Line Numbers
  1. dim mydate
  2. mydate = "2007-06-15"
  3.  
  4. Dim arr
  5. arr = Split( mydate, "-" )
  6.  
Access each array member with arr(0), arr(1), arr(2). You should be able to test on them to check if they are numbers and whether they fall in the correct range.
Thanks! After I posted it I figured I would do that until someone posted. Thanks for reassuring my idea lol. I had to do some more error testing though in case they did not use two hyphens or did not have the right lengths etc. Appreciate the help!
Jun 15 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by androtech | last post: by
reply views Thread by GaudaPrime | last post: by
30 posts views Thread by Dr John Stockton | last post: by
15 posts views Thread by Paul J. Ettl | last post: by
1 post views Thread by ToysNTreasures | last post: by
4 posts views Thread by IsdWeb | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.