Last active
March 7, 2017 20:34
-
-
Save PhilippMundhenk/17e780e2cbcdc054e48a3ad3e5faa13a to your computer and use it in GitHub Desktop.
In Excel, the date format depends on the locale setting of the computer, e.g. the formula =TEXT(TODAY(),"YYYY-MM-DD") only works correctly on computers set to English locales, and =TEXT(HEUTE(),"JJJJ-MM-TT") works on German computers. This VBA macro adds =PORTABLE_TODAY(), which fixes this problem and works on any computer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Function PORTABLE_TODAY() | |
Dim monthString As String | |
Dim dayString As String | |
Dim month As Integer | |
Dim day As Integer | |
month = Int(DatePart("m", Now())) | |
day = Int(DatePart("d", Now())) | |
If month < 10 Then | |
monthString = "0" & month | |
Else | |
monthString = month | |
End If | |
If day < 10 Then | |
dayString = "0" & day | |
Else | |
dayString = day | |
End If | |
PORTABLE_TODAY = DatePart("yyyy", Now()) & "-" & monthString & "-" & dayString | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment