I have a DateTime
represented as long (8 bytes), that came from DateTime.ToBinary()
, let's call it dateTimeBin
. Is there an optimal way of dropping the Time information (I only care for the date) so I can compare it to a start of day? Lets say we have this sample value as a start of day.
DateTime startOfDay = new DateTime(2020,3,4,0,0,0);
long startOfDayBin = startOfDay.ToBinary();
I obviously know I can always convert to a DateTime
object then get the date component. However, this operation is going to happen billions of times and every little performance tweak helps.
- Is there an efficient way of extracting the Date info of
dateTimeBin
without converting it toDateTime
? Or any arithmetic operation on thelong
that will return the date only? - Is there a way to match
startOfDay
(orstartOfDayBin
) anddateTimeBin
if they have the same date components? - Is there a way to see
if (dateTimeBin >= startOfDayBin)
, I don't think thelong
comparison is valid.
N.B. all the dates are UTC