Results 1 to 4 of 4

Thread: [RESOLVED] Date format

  1. #1

    Thread Starter
    Fanatic Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    826

    Resolved [RESOLVED] Date format

    I'm reading a date from an excel spreadsheet. The format in the spreadsheet is "mm/dd/yyyy". When I visually look at all the dates, in the selected column, I see all 10 characters.


    However, when I look at the date, in the program .Range("A" & i).value, I see 8 or 9 characters, depending on the date. For example, 01/01/2020 in the spreadsheet looks like 1/1/2020 in the program. 01/10/2020 looks like 1/10/2020, etc. I have the date in the program as "Dim dteDate As Date".


    I have tried to reformat the date as
    Code:
     dteDate = .Range("A" & i).Value
                dteDate = Format(Mid(dteDate, Len(dteDate) - 3), "yyyy")
    and I get an error msg Run-time error '13', Type mismatch


    I need to get just the year from the spreadsheet in "yyyy' format for further evaluation.


    Any help would be appreciated.


    Thanks

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,423

    Re: Date format

    Code:
    Dim dteDate As Date
    Dim lYear As Long
    
    dteDate = .Range("A" & i).Value
    lYear = Year(dteDate)

  3. #3

    Thread Starter
    Fanatic Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    826

    Re: Date format

    Wow, I never expected it to be just 2 simple lines of code. I started to parse the date, one char at a time until I got to the second "/".

    Thank you Arnoutdv.

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,423

    Re: [RESOLVED] Date format

    I assume you viewed the content of dteDate by doing debug.print dteDate, but this a conversion to the local datetime format.
    If you check the actual value with Debug.Print CDbl(dteDate) then you see the actual stored value.
    This floating point value can be use on all date conversion and formatting routines.

Posting Permissions

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



Click Here to Expand Forum to Full Width