Example input:
date1 = "2015-03-23 07:06:17.855000"
date2 = "2015-03-23 07:06:17.870000"
When I use
ans = datediff("s", date1, date2)
It produces the error: type mismatch
How can I fix this?
Example input:
date1 = "2015-03-23 07:06:17.855000"
date2 = "2015-03-23 07:06:17.870000"
When I use
ans = datediff("s", date1, date2)
It produces the error: type mismatch
How can I fix this?
Doesn't look like you've got a successful answer yet, so here's a possibility.
Dim t() as string
Dim d1 as long
Dim d2 as long
date1 = "2015-03-23 07:06:17.855000"
date2 = "2015-03-23 07:06:17.870000"
t = split(date1, ".") 'use the "." to split off the miliseconds
d1 = clng(t(2)) 'grab the milliseconds, convert it to long
t = split(date2, ".") 'use the "." to split off the miliseconds from the other date
d2 = clng(t(2)) 'grab the milliseconds, convert it to long
msgbox "Difference in milliseconds: " & cstr(d2-d1)
Try to convert dates stored as a string to date data type by using CDate("string_date")
:
Dim date1 As String, date2 As String, ans As Long
date1 = "2015-03-23 07:06:17.855000"
date2 = "2015-03-23 07:06:17.870000"
ans = datediff("s", CDate(Left(date1, Len(date1)-7)), CDate(Left(date2, Len(date2)-7)))
'returns 0, because both date and parts are the same!
The smallest unit of DateDiff function is a second.