728x90
Sub datetimeNow()
Date2 = DateTime.DateValue(DateTime.Now)
Debug.Print (Date2)
dateString = "20180619"
dateObjct = DateSerial(CInt(Left(dateString, 4)), CInt(Mid(dateString, 5, 2)), CInt(Right(dateString, 2)))
Debug.Print (dateObject)
End Sub
현재 날짜와 지정한 날짜의 차의를 계산 하고 싶을 때
1.현재 날짜를 dateObject로 만들어야 하고
2.원하는 날짜를 dateObject로 만들어서
그 차이를 계산 해야 한다.
그게 1번과 2번이다.
Sub test1()
res = calculateDay("2019-08-03", 2)
MsgBox (res)
End Sub
Function calculateDay(fromDate, addDay)
result = fromDate
result = DateAdd("d", addDay, fromDate)
calculateDay = result
End Function
날짜 더하기 dateAdd
날짜 빼기 dateSub
end.
728x90
'Excel VBA > VBA 예제' 카테고리의 다른 글
excel vba function 예제 - 사칙연산, 시트개수 세기 (0) | 2018.07.25 |
---|---|
열개수 숫자를 알파벳으로 ex)27 -> AA (0) | 2018.07.24 |
excel vba 날짜 다루기 now, string -> dateObject date add (0) | 2018.06.19 |
excel vba regexp (0) | 2018.06.02 |
excel vba array, redim예제 (0) | 2018.05.14 |
excel vba 차트 이동하기 (0) | 2018.04.21 |