user12203661
user12203661

Reputation:

Date Format for Macro

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.sstatic.net/MbaR9.png

here is my code:

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

Upvotes: 0

Views: 64

Answers (2)

Josiah Bryan
Josiah Bryan

Reputation: 66

I believe the following should add the desired dot:

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

Upvotes: 1

SnowGroomer
SnowGroomer

Reputation: 695

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

Upvotes: 4

Related Questions