“Ago” date/time functions in Ruby/Rails

I was wondering, if theres a way in rails to calculate time stamp like – half a minute ago, 2 minute ago, 1 day ego etc. Something like twitter real time date stamp.

I want to know if ruby/rails has a pre-built function for such date-time conversion??

Display datetime like 1 hour ago, 5 hours ago, 3 days ago, [duplicate]

Possible Duplicate: How do you do relative time in Rails? I want to display the datetime like this: 30 seconds ago 1 hour ago 9 hours ago 2 days ago 1 year ago .. Is this built in or should I write

python ‘x days ago’ to datetime

I have strings that show a date in the following format: x minutes/hours/days/months/years ago I need to parse that to a datetime using python. It seems dateutil can’t do it. Is there a way to do it?

Get 1 month ago from current datetime

My Code as below :- I’m trying to get 1 month ago date and time but what i get from this was 2013 11 02 which the correct one should be 2013 12 02 pls help. Calendar calendar = Calendar.getInstance();

Python: get datetime for ‘3 years ago today’?

This must be a duplicate (and documented), but I can’t find the answer via Google. In Python, how do I get a datetime object for ‘3 years ago today’? Thanks! UPDATE: FWIW, I don’t care hugely about ac

Is there a Django template filter that turns a datetime into “5 hours ago” or “12 days ago”?

Let’s say I have a datetime. I do this: Submitted on {{ post.date|date:D. M d, P }} This actually prints the date. However, what if I want it to say, 4 hours ago or 55 days ago or 2 months ago

XSL – Using DateTime Functions

I have an XSL document which I am in the process of creating but when I try to use the DateTime functions specified here: http://www.w3schools.com/xpath/xpath_functions.asp Such as dateTime or year-fr

Display “time ago” instead of datetime in PHP Codeigniter

I would like to display a time format like twitter and FB (Posted 3 hours ago, Posted 2 minutes ago and so on…) I’ve tried this piece of code without success : function format_interval($timestamp,

How to create a DateTime equal to 15 minutes ago?

I need to create a DateTime object that represents the current time minus 15 minutes.

Select * to table where datetime is 24 hours ago

I need to select all data in table created not less than 24 hours ago. Anyone know how to do this?

Best way to convert DateTime to “n Hours Ago” in SQL

I wrote a SQL function to convert a datetime value in SQL to a friendlier n Hours Ago or n Days Ago etc type of message. And I was wondering if there was a better way to do it. (Yes I know don’t

Answers

You can use:

10.minutes.ago
2.days.since

Or in your views you have the helpers:

distance_of_time_in_words(from_time, to_time)
time_ago_in_words(from_time)

Check the API for details and more options.

You can use available methods to get the time in past or future using ago, since alias for from_now and many available methods

Time.current
#=> Tue, 20 Sep 2016 15:03:30 UTC +00:00

2.minutes.ago
#=> Tue, 20 Sep 2016 15:01:30 UTC +00:00

2.minutes.since
#=> Tue, 20 Sep 2016 15:05:30 UTC +00:00 

1.month.ago
#=> Sat, 20 Aug 2016 15:03:30 UTC +00:00

1.year.since
#=> Wed, 20 Sep 2017 15:03:30 UTC +00:00 

Check all the available methods in Time class

“Ago” date/time functions in Ruby/Rails

I was wondering, if theres a way in rails to calculate time stamp like – half a minute ago, 2 minute ago, 1 day ego etc. Something like twitter real time date stamp.

I want to know if ruby/rails has a pre-built function for such date-time conversion??

Display datetime like 1 hour ago, 5 hours ago, 3 days ago, [duplicate]

Possible Duplicate: How do you do relative time in Rails? I want to display the datetime like this: 30 seconds ago 1 hour ago 9 hours ago 2 days ago 1 year ago .. Is this built in or should I write

python ‘x days ago’ to datetime

I have strings that show a date in the following format: x minutes/hours/days/months/years ago I need to parse that to a datetime using python. It seems dateutil can’t do it. Is there a way to do it?

Get 1 month ago from current datetime

My Code as below :- I’m trying to get 1 month ago date and time but what i get from this was 2013 11 02 which the correct one should be 2013 12 02 pls help. Calendar calendar = Calendar.getInstance();

Python: get datetime for ‘3 years ago today’?

This must be a duplicate (and documented), but I can’t find the answer via Google. In Python, how do I get a datetime object for ‘3 years ago today’? Thanks! UPDATE: FWIW, I don’t care hugely about ac

Is there a Django template filter that turns a datetime into “5 hours ago” or “12 days ago”?

Let’s say I have a datetime. I do this: Submitted on {{ post.date|date:D. M d, P }} This actually prints the date. However, what if I want it to say, 4 hours ago or 55 days ago or 2 months ago

XSL – Using DateTime Functions

I have an XSL document which I am in the process of creating but when I try to use the DateTime functions specified here: http://www.w3schools.com/xpath/xpath_functions.asp Such as dateTime or year-fr

Display “time ago” instead of datetime in PHP Codeigniter

I would like to display a time format like twitter and FB (Posted 3 hours ago, Posted 2 minutes ago and so on…) I’ve tried this piece of code without success : function format_interval($timestamp,

How to create a DateTime equal to 15 minutes ago?

I need to create a DateTime object that represents the current time minus 15 minutes.

Select * to table where datetime is 24 hours ago

I need to select all data in table created not less than 24 hours ago. Anyone know how to do this?

Best way to convert DateTime to “n Hours Ago” in SQL

I wrote a SQL function to convert a datetime value in SQL to a friendlier n Hours Ago or n Days Ago etc type of message. And I was wondering if there was a better way to do it. (Yes I know don’t

Answers

You can use:

10.minutes.ago
2.days.since

Or in your views you have the helpers:

distance_of_time_in_words(from_time, to_time)
time_ago_in_words(from_time)

Check the API for details and more options.

You can use available methods to get the time in past or future using ago, since alias for from_now and many available methods

Time.current
#=> Tue, 20 Sep 2016 15:03:30 UTC +00:00

2.minutes.ago
#=> Tue, 20 Sep 2016 15:01:30 UTC +00:00

2.minutes.since
#=> Tue, 20 Sep 2016 15:05:30 UTC +00:00 

1.month.ago
#=> Sat, 20 Aug 2016 15:03:30 UTC +00:00

1.year.since
#=> Wed, 20 Sep 2017 15:03:30 UTC +00:00 

Check all the available methods in Time class