2

Is there a way in Haskell to parse a date from a string of format "YYYY-MM-DD"? That is, something like parseDateFromString 2016-10-20 that would then return a date in some commonly used Haskell date format.

1 Answer 1

5

Data.Time provides parseTimeM, which is a bit unwieldy. I might be overlooking a simpler alternative.

> import Data.Time
> parseTimeM False defaultTimeLocale "%Y-%m-%d" "2016-10-20" :: Maybe UniversalTime
Just 2016-10-20 00:00:00

The return type is fairly open. You can return the value to any monad; Maybe seemed like a good example to reflect an answer or a failure to parse the string. The type wrapped by Maybe is any instance of the ParseTime typeclass; UniversalTime is defined in the library.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.