Datediff Function

     

  • Provides the difference between two dates
  •  

    Private Sub CommandButton1_Click()
    Range("A1").Value = DateDiff("d", "1-jan-2015", "1-March-2015")
    MsgBox DateDiff("d", "1-jan-2015", "1-March-2015")
    Range("A2").Value = Date
    Range("B2").Value = "1-Oct-2016"
    'Difference in terms of Days
    Range("C2").Value = DateDiff("d", Range("A2"), Range("B2"))
    'Difference in terms of weeks
    Range("d2").Value = DateDiff("ww", Range("A2"), Range("B2"))
    'Difference in terms of hours
    Range("E2").Value = DateDiff("h", Range("A2"), Range("B2"))
    'Difference in terms of Seconds
    Range("F2").Value = DateDiff("s", Range("A2"), Range("B2"))
    'Difference in terms of Seconds
    Range("G2").Value = DateDiff("m", Range("A2"), Range("B2"))
    End Sub

     

    Download The Workbook