4

I have the following issue: I want to get the timestamp of yesterday on a specific time.

With what I've come up so far is:

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

I'm new to Ruby so that's probably the reason why my Ruby code looks so similar to PHP :)

Maybe it's a help when I say I would like something like this PHP solution in Ruby:

mktime(23,59,59,date("m",time()),date("d",time()-86400),date("Y",time()));
Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
TehQuila
  • 628
  • 1
  • 8
  • 19

2 Answers2

4

Is it a problem to 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
tokland
  • 66,169
  • 13
  • 144
  • 170
2
require 'date'
Date.today.to_time - 1  #=> 2011-11-14 23:59:59
steenslag
  • 79,051
  • 16
  • 138
  • 171