Skip to content

Instantly share code, notes, and snippets.

@SeongilRyu
Created January 9, 2019 06:13
Show Gist options
  • Save SeongilRyu/cf005b16bbd80be4f96955b73482f1de to your computer and use it in GitHub Desktop.
Save SeongilRyu/cf005b16bbd80be4f96955b73482f1de to your computer and use it in GitHub Desktop.
Functions of Date and time
Sub show_datetime()
Dim adate As Variant
adate = Date
Debug.Print adate ''2019-01-09
Debug.Print Year(adate) ''2019
Debug.Print Month(adate) ''1
Debug.Print Day(adate) ''9
Debug.Print DateAdd("yyyy", 1, adate) ''2020-01-09
Debug.Print DateAdd("m", 1, adate) ''2019-02-09
Debug.Print DateAdd("d", 1, adate) ''2019-01-10
'''
Dim fromDate, toDate As Variant
fromDate = "2019-01-01 00:00:00"
toDate = "2020-01-01 23:59:00"
Debug.Print DateDiff("yyyy", fromDate, toDate) '' 1
Debug.Print DateDiff("m", fromDate, toDate) '' 12
Debug.Print DateDiff("d", fromDate, toDate) '' 365
''
Dim atime As Variant
atime = Now
Debug.Print atime ''2019-01-09 오후 3:09:51
Debug.Print Hour(atime) ''15
Debug.Print Minute(atime) ''9
Debug.Print Second(atime) ''51
Debug.Print DateAdd("h", 1, atime) ''오후 1:00:00
Debug.Print DateAdd("n", 1, atime) ''오후 12:01:00
Debug.Print DateAdd("s", 1, atime) ''오후 12:00:01
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment