timWhit
timWhit

Reputation: 645

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.

Upvotes: 43

Views: 43150

Answers (3)

Rohit Jain
Rohit Jain

Reputation: 139

To get the String you're looking for

your_date.strftime("%F")

below link u can get more type of date. http://ruby-doc.org/core-2.2.0/Time.html#method-i-strftime

Upvotes: 1

Ved
Ved

Reputation: 3500

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

Upvotes: 92

David Sulc
David Sulc

Reputation: 25994

To get the String you're looking for

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

Not sure what you mean about modifying the database?

Upvotes: 18

Related Questions