I have a String which contains the following string 2012-03-06 00:00:00 UTC
I want to change it into a date object so that is should look like this 03-06-2012
and the same is to be converted in String 03-06-2012
so that the jquery datepicker can take it.
All this conversion needs to be done at view .html.erb
Date.parse("2012-03-06 00:00:00 UTC").strftime("%d-%m-%Y")
You can do this
date = DateTime.now
puts date.to_date.to_s
which gives "2013-08-21"
date = Date.parse('2012-03-06 00:00:00 UTC')
# => Tue, 06 Mar 2012
date.strftime('%d-%m-%Y')
# => "06-03-2012"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With