Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VBA Convert date to string

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")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading