Transforming Elixir date into date for a CSV file (ISO)

Hello, I am attempting to change a date from my Postgres database into a date I can put in a CSV file. However; when I use the Date.to_iso8601(~N[2000-02-28 10:00:23]) function, I get the time part of the datetime truncated off. How do I do the exact same functionality but keep the whole datetime?

I should add that DateTime.to_iso8601 does not return a valid CSV format.

CSV do not define date format at all, so I do not know what you expect.

1 Like

ISO formatted date is expected or something like this yyyy-MM-dd HH:mm:ss

Use NaiveDateTime.to_iso8601 if you want the whole datetime and DateTime.to_iso8601 if you also need timezone offset information. The Date module handles just date related functionality.

5 Likes

There is no valid CSV format. :slight_smile:

Go with what @LostKobrakai suggested: NaiveDateTime.to_iso8601.

3 Likes