I have a question about the dates of beginning and Stringin Haskell.
I need to get a part of the date (year, month or day) as Stringin Haskell. I found out that if I write the following two lines in GHCi
Prelude> now <- getCurrentTime
Prelude> let mon = formatTime defaultTimeLocale "%B" now
that monhas a type String. However, I cannot include this in a function. I tried for example the following:
getCurrMonth = do
now <- getCurrentTime
putStrLn (formatTime defaultTimeLocale "%B" now)
But this returns a type IO (), and I need String(also not IO String, only String).
I understand that the operator docreates a monad that I do not want, but I could not find any other solution to get the date in Haskell.
So, is there a way to write such a function?
Thanks in advance for your help!