-
Feb 11th, 2025, 07:54 AM
#1
Thread Starter
Fanatic Member
[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
-
Feb 11th, 2025, 07:56 AM
#2
Re: Date format
Code:
Dim dteDate As Date
Dim lYear As Long
dteDate = .Range("A" & i).Value
lYear = Year(dteDate)
-
Feb 11th, 2025, 08:29 AM
#3
Thread Starter
Fanatic Member
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.
-
Feb 11th, 2025, 09:11 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|