To replicate, do:
as.numeric(difftime(
strptime("12:00 AM", "%I:%M %p", tz = "Europe/Brussels" ),
strptime("2:00 AM", "%I:%M %p", tz = "Europe/Brussels" ),
units='hours'))
# [1] NA
Given the behavior you're getting, I expect you are running into a daylight savings time issue because you are in a locale that has a daylight saving time change on the last Sunday of March. There is no "roll" argument for strptime
or difftime
so you have to set the time zone manually to a location that isn't in the middle of a time change in that period (and if you want to account for it, add an hour).
as.numeric(difftime(
strptime("12:00 AM", "%I:%M %p", tz = "UTC" ),
strptime("2:00 AM", "%I:%M %p", tz = "UTC" ),
units='hours'))
# [1] -2