Solved

CDate() function

Posted on 2004-04-20
3
1,435 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

895 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

11 Experts available now in Live!

Get 1:1 Help Now