Chinedu Lloyd Abalogu Chinedu Lloyd Abalogu - 11 months ago 78
MySQL Question

Rails DateTime helper logic

Quick question. I am using the distance_of_time_in_words helper to check how many days an object was created. This works fine but I dont want it to have to go 24 hrs before it counts a day but want it to count "1" day once it is "00:00"

eg distance_of_time_in_words("2016-08-11 11:00", "2016-08-12 00:00") should be 1 day but it is 13 hrs

I want that once it passes "00:00" it should count as a 1 day?


You may be able to use


time_ago_in_words allows you to forgo adding the 'now' time* and by moving the created-at date back to midnight, you'll cross the one-day mark at the next midnight. According to the API doc, it should give you 'round' days for anything over a day, which sounds like what you're after.

*You can continue to use distance_of_time_in_words if you're not comparing to the current time.