Dates - Randomly generating DateTime values

I have two DateTimes, dt1 < dt2. What is a reasonable way to randomly generate a DateTime that is in between dt1 and dt2? I started off by trying

dt3 = rand(dt1.instant.periods.value : dt2.instant.periods.value).

This gives me a randomly generated Int64 representation, but I do not know how to properly convert it back to a DateTime. Calling DateTime(dt3) doesn’t seem to parse correctly, presumably because it needs dt3 to be of type Millisecond as opposed to Int64, but I do not know how to convert from Int64 back to Millisecond.

You could do

unix2datetime(rand(datetime2unix(dt1) : datetime2unix(dt2)))

but I suspect there’s a more efficient way

It doesn’t feel very elegant and there is probably a better way but this is the way I came up with.

t0 = DateTime(2018,9,19)
t1 = DateTime(2018,9,19,10)
n = 5 # Number of values

t_random = t0 + Dates.Millisecond.(floor.(rand(n)*(t1-t0).value))