Answer the question
In order to leave comments, you need to log in
How to subtract UTCTIme from UTCTime and get the difference in days?
H:p:// I want to subtract UTCTime from UTCTime. I found this function:
diffUTCTime :: UTCTime -> UTCTime -> NominalDiffTime
But I get the difference in NominalDiffTime, and I need to get the difference in days
Is there any function for that?
Answer the question
In order to leave comments, you need to log in
The most frontal way is to use diffTimeToPicoseconds and then divide by some factor equal to the number of picoseconds in a day.
NominalDiffTime is, among others, a Fractional, so you can divide your result with nominalDay:
Prelude Data.Time.Clock> myDiffTime / nominalDay
2.314814814814s
You can use its RealFrac instance to round, floor, etc. it:
Prelude Data.Time.Clock > round $ myDiffTime / nominalDay
2
Prelude Data.Time.Clock > truncate $ myDiffTime / nominalDay
2
Prelude Data.Time.Clock > floor $ myDiffTime / nominalDay
2
Prelude Data.Time.Clock > ceiling $ myDiffTime / nominalDay
3
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question