Solved

CDate() function

Posted on 2004-04-20
3
1,431 Views
Last Modified: 2013-12-26
Does anyone know why CDate(05/08/0001) is returning me 05/08/2001...And the IsDate function returns this as a valid date as well...I need a function that will return false, because this is not a valid date, or at least I dont think it is....
0
Comment
Question by:BigBadBarnes
3 Comments
 
LVL 9

Expert Comment

by:dancebert
ID: 10872957
To answer your second question, 05/08/0001 is a valid date: May eighth in the year one.
0
 
LVL 39

Accepted Solution

by:
appari earned 125 total points
ID: 10874810

In Microsoft Windows, the range of valid dates is January 1, 100 A.D. through December 31, 9999 A.D

and the years less than 100 are translated to a year with a prefix 19 or 20 based on your regional settings. in your systems regional settings if you see the date settings tab you can see how to interpret 2 digit years.

all date functions see if the string can be converted to a valid date or not. so IsDate function returns true for 05/08/0001 becoz its converting the date to 05/08/2001

if you check cdate("05/08/0031") it reutrns you 05/08/1931.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 10875283
What format of date are you using ? American or european layout ? (so mm/dd/yyyy or dd/mm/yyyy)
For example:
'if 2/12/99 is 2nd December or 12th Febuary if you don't know which system your machine is using

It will return both valid.
Suppose you have on  your system the american format, then 12/13/2004 will be valid, but 13/12/2004 will be invalid (while you can suppose that it's the other way).

You can also format your date and then validate it with isDate

Here you can find a function to see if a date string is valid using regional date settings
http://www.vb-helper.com/howto_validate_date_international.html
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now