473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 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 2942
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

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

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
0
by: GaudaPrime | last post by:
Hi, I have an Oracle 8i instance which has somehow managed to store the 29th of February 2005 in a date field. As 2005 isn't a leap year this is an invalid date. SQL> select NEXTTRIG_DATE,...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
15
by: Paul J. Ettl | last post by:
Two questions: I use var date1 = new Date(); to get todays date. But how can I get yesterdays date? Furthermore I use
1
by: Rob | last post by:
How can I create a validation rule for only allowing two specific dates but with variable years: 1/1/yyyy or 12/1/yyyy so only the dates 1/1/2004 or 1/1/1999 or 12/1/2001 etc. I tried...
1
by: ToysNTreasures | last post by:
Hi, I'm working on a class project in which I have to create a simple hotel reservation database using Access. I've created a couple of tables and queries that allow a user to determine room...
11
by: carriolan | last post by:
Hi I have a very simple problem indeed, but I am unable to solve it. I am inputing a short date into an unbound text box with a short date input mask. I am in the UK so my date format is...
3
by: Robert | last post by:
I need to set up a query that will pick out records for the current winter season. I.e., each season runs from October 1 until March 31. The catch is, the year can't be hard coded. So, if the...
4
by: IsdWeb | last post by:
Hello, I am a newbie to coding and need some help. I am trying to figure out why the following code is not producing the correct Julian date. Any suggestions? Also, I am trying to understand...
2
by: DrSporkeh | last post by:
Hai everyone, i need some help :o basically im trying to set some validation rules for an 'employees' table. firstly i've set it to you have to be 16 to work here under 'Date Of Birth' ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.