aboutsummaryrefslogtreecommitdiff
path: root/challenge-132/eric-cheung/excel-vba/ch-1.bas
blob: 3f187820bda177d767d9ebd7ae780be3dcaf5e99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Attribute VB_Name = "ModTask_01"
Option Explicit
Public Const strMyTitle As String = "Eric Cheung"

Sub Task_01()

    Dim strMsg As String
    Dim nDayAge As Long
    Dim strDateInput As String, strToday As String
    Dim Date_01 As Date, Date_02 As Date
    
    '' strDateInput = "2021-09-18" '' Example 1:
    '' strDateInput = "1975-10-10" '' Example 2:
    strDateInput = "1967-02-14" '' Example 3:
    
    strToday = "2021-09-22"
    
    nDayAge = DateDiff("d", strDateInput, strToday)
    
    Date_01 = DateAdd("d", -nDayAge, strDateInput)
    Date_02 = DateAdd("d", nDayAge, strToday)
    
    strMsg = Format(Date_01, "yyyy-mm-dd") & ", " & Format(Date_02, "yyyy-mm-dd")

    MsgBox strMsg, vbOKOnly, strMyTitle
    
End Sub