Ruby - yesterday's time stamp before a specific time

I have the following problem: I want to get yesterday’s timestamp at a specific time.

With what I have found so far:

Time.local(Time.now.strftime("%Y"), Time.now.strftime("%m"), (Time.now.strftime("%d")-1), 23, 59, 59).tv_sec 

I am new to Ruby, so probably the reason my Ruby code looks just like PHP :)

Maybe this will help when I say that I would like something like this PHP solution in Ruby:

 mktime(23,59,59,date("m",time()),date("d",time()-86400),date("Y",time())); 
+4
source share
2 answers

Should I use Activesupport?

 require 'active_support' Date.yesterday.end_of_day # .to_i to get the timestamp in seconds #=> Mon Nov 14 23:59:59 +0100 2011 
+4
source
 require 'date' Date.today.to_time - 1 #=> 2011-11-14 23:59:59 
+2
source

Source: https://habr.com/ru/post/1381294/


All Articles