Variable datetimes

Hi, I have to store dates inside a DB, but unfortunately my date representation can be a string like "2007" but also a normal date string, like "2007-8-12" ...
I want to use Date/DateTime objects because they are easy to manipulate, but Date.parse can parse only the second format, not the first (which is understandable ...).
How can I solve this problem ? Storing something like 2007-0-0 or 2007-1-1 is ok for me, like in
I can check if the string contains '-' and if not do something like but I don't like this solution ...

Chiacchiera con i tuoi amici in tempo reale!*

string = ‘2007-01-01’*string.split(’-’).map(&:to_i))

Thank you, but my problem is that my input is only '2007', if I had a string like '2007-01-01' I could use Date.parse :slight_smile:

Chiacchiera con i tuoi amici in tempo reale!*

irb:> string = '2007'
=> "2007"
=> 2007-01-01

This seems to actually do what you want it to...