Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Dec 2001
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    CDATE function (97 & 2000)

    I have an Access database created by someone long gone (aargh) for our ER dept. It is suddenly doing odd things with the dates and in trying to track down the problem I have found that the person used the built-in Function CDATE...I can't find anything on this function. Only that the syntax is CDATE(Date)... Anyone know this function and what is using and returning?
    An example of the offending code is below...with a fix that I found made at least one of the reports work correctly. But I'd like to know why it fixed it and what this function is doing.
    orig entry---> Month: CDate(Format([DATE],"mm/yy"))
    Entry that fixed things---> Month: CDate(Format([DATE],"mm/""01""/yy"))

    thanks,
    lori

  2. #2
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Frederick, Maryland, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CDATE function (97 & 2000)

    The CDate function is a data-type conversion function that converts a numeric value to a Date value. The usage syntax is CDate(NumValue). The NumValue argument can be any numeric or String value. Beyond that, I've never used it. Good luck!

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: CDATE function (97 & 2000)

    rhconley is correct as to it's function - is DATE a field in a table? That's generally not a good idea, as the current date function in Access is Date(), and in VB you refer to it at Date. What the line of code that you started with did was simply format the DATE field as 02/02 for example. It's not clear to me why the CDate was used, as the Format function does essentially that, but ... Your new code sets the Month Field to explicitly be 02/01/02 for example (if DATE were 02/08/02) and then display it that way I presume. The reason for doing this isn't clear, but maybe they thought it would be easier to put in criteria. Usually if you want to see all of the records for a month, we use a between clause and make the user type both dates. Things can get tricky if you carry a timestamp however, as a between 2/1/02 and 2/28/02 will miss timestamp records for 2/28, as the between clause is construed to mean >=2/01/02 12:00:00AM and <=2/28/02 12:00:00AM. Hope this doesn't confuse the issue too much.
    Wendell

  4. #4
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Richland, Washington, USA
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CDATE function (97 & 2000)

    Here's a little more commentary that may be helpful...

    As mentioned by the others, CDate converts its argument (string or numeric) to a data-type of "Date". Format() produces a string representation of a date (as it's used here, anyway).

    Your original entry appears to be an unintentional example of careless programming and is an interesting Y2K (actually Y2K+2) artifact. The problem stems from how Cdate converts a string to a Date data-type when only two numbers are specified (as is the case in your original entry).

    Format([DATE],

  5. #5
    Lounger
    Join Date
    Dec 2001
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CDATE function (97 & 2000)

    Just wanted to say thankyou for the responses. I really appreciate it! You guys are the best.
    Lori

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •