Solved

CDate() function

Posted on 2004-04-20
3
1,451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

707 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