Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - get date from date & time stamp

In my Rails database, I have a timestamp that looks like this 2010-12-22 18:21:46 UTC. I need a way to just get the date 2010-12-22 from it without re-doing the database.

like image 831
timWhit Avatar asked Jan 15 '11 18:01

timWhit


2 Answers

Try time.to_date to extract date component from your timestamp.

like image 189
Ved Avatar answered Nov 18 '22 02:11

Ved


To get the String you're looking for

your_date.strftime("%Y-%m-%d")

Not sure what you mean about modifying the database?

like image 22
David Sulc Avatar answered Nov 18 '22 02:11

David Sulc