?
Solved

CDate() function

Posted on 2004-04-20
3
Medium Priority
?
1,458 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 375 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

777 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