0

I have tried the following but not working,

Dim my_date_string As String
Dim my_date_date As Date

my_date_string = "22.10.2020"
my_date_date = CDate(my_date_string)

Debug.Print my_date_string
Debug.Print my_date_date

Also tried with,

my_date_date = Format(my_date_string, "DD.MM.YYYY")
2
  • 2
    my_date_date = CDate(Replace(my_date_string, ".", "/")) Commented Nov 19, 2021 at 10:25
  • You try converting string to date... Your code works only with regionalization involving that type of data (in the string) as default. Doing what @braX recommended works in all cases, anyhow... Commented Nov 19, 2021 at 10:35

1 Answer 1

1

CDate does not understand periods as separators.

If you need them to be periods in your String variable for some reason, just replace them like this:

my_date_date = CDate(Replace(my_date_string, ".", "/"))

If your variable does not have periods in it, the Replace function will simply do nothing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.