Ok, what you want is not impossible, but you have to think about the date 1/2/04. What is this date? IS it 1st Feb or 2nd Jan?? You need to offer your user one way to enter the date, dependant on their regional settings, so if american, it is 2nd Jan and if English, it is 1st Feb. Or you just stick to one date type all the way through the project.
As to valiation, you can use format("dd\/MM\/yyyy", myDate) to change the input to a valid date.
BiggerBrother
Thanks for the reply.
Unfortunately I have to use the different formats for the date.
1/2/04 would be a valid date and not matter if it was english or american.
I think BB knows this - what he's trying to say is that the first part of validating whether or not something is a date is to understand how the user deals with dates - which depends to a large extent on where in the world they are.
What he's saying is take something like 13/03/2004. If you're in England, that's going to be taken to denote 13th of March, which is quite valid so no problems there... However, if you were in the United States, you would read "13/03/2004" as being the third day in the thirteenth month - which is clearly not a good idea.
Essentially then, whether or not a date value is valid depends very much where you are - and this is why BB has mentioned the locale stuff.
I would recommend that you write code to split out the day, month and year from your date string (remembering to support things like "02/04/2004" and "02-Apr-2004" and "02-April-04"), and then work out from that whether you have a valid date.
The only tricky bit of course is February, because of the leap year having the extra day - which you'll need to allow for in your code.
As a rough guide, if the year is divisible by 4, it's a leap year. If it's divisible by 100 then it's not a leap year, though if it's divisible by 400 it is...
And you're quite right about IsDate - it's a bit of a joke.
mmilan
Thanks for the post,
Your advice is good, it looks like I am forced to break up the string using the split command. I'm sure this may create other issues.
- Use a Date Picker, which gives you a drop down month planner, where you can then select the date you want.
- Create your own control, using two textboxes and a combobox. In the combobox, place all the months, and then place a text box on either side. Only all numeric values in the textboxes, and when the date is entered, the user is forced to enter the date the way you want.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.