Date Format for Macro

63 views Asked by At

I wrote a Macro to simplify a process at work.

I am trying to figure out how to fix this date so when the macro is run it isn't missing an "."

ex) https://i.stack.imgur.com/MbaR9.png

here is my code:

 Dim currentDate As String
    currentDate = Left(Replace(Date, "/", "."), 5) + Right(Date, 2)
2

There are 2 answers

0
SnowGroomer On

To format date as a string use Format function and specify the format in a string. For instance:

Format(Date, "yyyy-mm-dd") 'gives 2020-01-08
2
Josiah Bryan On

I believe the following should add the desired dot:

Dim currentDate As String currentDate = Left(Replace(Date, "/", "."), 5) & "." & Right(Date, 2)