How get yesterday in Haskell? Current date - 1 day?

Viewed 465

How get yesterday in Haskell? For the current day - of course it works like this:

date :: IO (Integer,Int,Int) -- :: (year,month,day)
date = getCurrentTime >>= return . toGregorian . utctDay

But for yesterday? Does that work with diffUTCTime?

With sql:

select current date, current date - 1 day from sysdba.routine 
08.11.2018 07.11.2018

But with Haskell?

1 Answers

You can use the addUTCTime :: NominalDiffTime -> UTCTime -> UTCTime function with as difference -nominalDay. For example:

Prelude Data.Time.Clock> fmap (addUTCTime (-nominalDay)) getCurrentTime
2018-11-07 15:27:57.8510597 UTC

or when you want to obtain the Gregorian date:

Prelude Data.Time.Clock Data.Time.Calendar> fmap (toGregorian . utctDay . addUTCTime (-nominalDay)) getCurrentTime
(2018,11,7) 
Related