Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: How I can get yesterday's date?

How can I get yesterday's date?

maybe:

@get_time_now    = Time.now.strftime('%m/%d/%Y') / 86400  

or

@get_time_now    = Time.now.strftime('%m/%d/%Y') - 1.day 

or

@get_time_now    = Time.now. / 86400  

86400 = 1 day, right? (60 * 60 * 24)

like image 831
Michael Gorsky Avatar asked Jun 27 '11 07:06

Michael Gorsky


People also ask

How do I find yesterday's date?

How do you get yesterdays' date using JavaScript? We use the setDate() method on yesterday , passing as parameter the current day minus one. Even if it's day 1 of the month, JavaScript is logical enough and it will point to the last day of the previous month.

How do I get the past date in flutter?

How to select previous or next dates based on the selected date in the Flutter Date Range Picker (SfDateRangePicker) In the Flutter Date Range Picker, you can highlight the before and after date ranges of the selected date by using onSelectionChanged callback of the Flutter date range picker.


1 Answers

Rails

For a date object you could use:

Date.yesterday 

Or a time object:

1.day.ago 

Ruby

Or outside of rails:

require 'date'  Date.today.prev_day 
like image 188
Andrew Nesbitt Avatar answered Oct 18 '22 10:10

Andrew Nesbitt