Christian-G
Christian-G

Reputation: 2361

Convert db date to rfc3339

I have a form that collects datetime as follows: 2013-05-21 00:00:00 UTC

This needs to be converted to a XML compatible format. I tried using the .rfc3339 method:

DateTime.rfc3339('2013-05-21 00:00:00 UTC')

I get the following error: convert ActiveSupport::TimeWithZone to String

Any suggestions?

Upvotes: 0

Views: 1099

Answers (1)

fbonetti
fbonetti

Reputation: 6672

The DateTime::rfc3339 class method parses an RFC3339 string and returns a date object. To convert a date object into an RFC3339 string, use the following code:

DateTime.parse('2013-05-21 00:00:00 UTC').rfc3339

Upvotes: 2

Related Questions