updated_at not today?

28 views
Skip to first unread message

Fresh Mix

unread,
Jun 29, 2014, 8:43:13 AM6/29/14
to rubyonra...@googlegroups.com
How can you verify that it has not been updated today?

if @post.updated_ad "is not today"
@post.counter = @post.counter + 1
@post.save
end

--
Posted via http://www.ruby-forum.com/.

Robby O'Connor

unread,
Jun 29, 2014, 8:48:41 AM6/29/14
to rubyonra...@googlegroups.com

Check if the current date is equal to that? 

--Rob
Sent from my phone...excuse any typos please!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e7f62059ee82c3da9a4cab0763412b40%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Colin Law

unread,
Jun 29, 2014, 8:54:57 AM6/29/14
to rubyonra...@googlegroups.com
On 29 June 2014 13:41, Fresh Mix <li...@ruby-forum.com> wrote:
> How can you verify that it has not been updated today?

The first question is what do you mean by today? Note in particular
that your date may not be the same as mine if we are in different
timezones.

Colin

Fresh Mix

unread,
Jun 29, 2014, 9:15:58 AM6/29/14
to rubyonra...@googlegroups.com
Colin Law wrote in post #1151057:

> The first question is what do you mean by today? Note in particular
> that your date may not be the same as mine if we are in different
> timezones.


Same year, same month and same date. And I think that all of my visitors
are in the same time zone and it is not so important, about the same
day...

Robby O'Connor

unread,
Jun 29, 2014, 9:20:15 AM6/29/14
to rubyonra...@googlegroups.com

This is basic ruby...


--Rob
Sent from my phone...excuse any typos please!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

Fresh Mix

unread,
Jun 29, 2014, 9:31:18 AM6/29/14
to rubyonra...@googlegroups.com
if @post.updated_at.strftime("%d-%m-%Y") !=
Time.now.strftime("%d-%m-%Y")

Or is there better way?

Walter Lee Davis

unread,
Jun 29, 2014, 9:32:39 AM6/29/14
to rubyonra...@googlegroups.com
Read up on the Date class. You can compare dates directly, and you have the whole range of < = > operators to work on them.

Walter
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/90923dbc34a739dd822264ed051931e1%40ruby-forum.com.

Colin Law

unread,
Jun 29, 2014, 9:50:22 AM6/29/14
to rubyonra...@googlegroups.com
On 29 June 2014 14:27, Fresh Mix <li...@ruby-forum.com> wrote:
> if @post.updated_at.strftime("%d-%m-%Y") !=
> Time.now.strftime("%d-%m-%Y")
>
> Or is there better way?

Those give you the dates in UTC, which may not be the same as the
local timezone date.

Colin
Reply all
Reply to author
Forward
0 new messages