What is the syntax to return the difference between two times?

DateDiff (interval, date1, date2, firstdayofwk, firstdayofyr)
‘interval – can be one of the following listed in bullet points; mandatory
‘date1, date2 are mandatory
‘firstdayofweek – can be values 1-7 for Sunday-Saturday, or 0 for system’s version; optional parameter
‘firstdayofyear – really useless optional parameter, just ignore it

Interval values

  • d – day of the year.
  • m – month of the year
  • yyyy -Year
  • w -Weekday
  • ww -week
  • q -quarter
  • h -Hour
  • n -Minute
  • s –Second
‘examples
MsgBox (DateDiff("yyyy", #2/23/2024#, #12/5/2034#)) '10 years
MsgBox (DateDiff("d", #2/1/2050#, #1/28/2050#)) '-4 days
MsgBox (DateDiff("h", "01-Jan-20 00:00:00", "01-Jan-20 23:59:00")) '23 hours
MsgBox (DateDiff("n", "01-Jan-20 12:00:00", "01-Jan-20 12:59:00")) '59 minutes
MsgBox (DateDiff("d", Date, txtDate.Value)) 'difference between a user inputted date and today

 

Advertisements