Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
3 answers
97 views

How to convert a Date to the midday Time in UTC in Ruby-on-Rails, regardless of the timezone?

I have a Date instance in Ruby-on-Rails. I would like to convert it into the midday in Time in UTC. How can I do it? I thought this would work. date = Date.new(2024, 10, 20) time = date.to_time + Time....
Masa Sakano's user avatar
  • 2,277
0 votes
1 answer
112 views

Compare times on separate dates in Ruby/Rails?

I have 3 different TimeWithZone objects: from = Mon, 20 Apr 2020 00:00:00.000000000 UTC +00:00 to = Mon, 20 Apr 2020 23:59:59.000000000 UTC +00:00 event = Sat, 01 Jan 2000 07:00:00.000000000 UTC +00:...
Dylan Richards's user avatar
1 vote
1 answer
304 views

How to display date variables on site using Ruby on Rails?

I wanted to display my time variables to see when pass has started and when will it end but don't know how and couldn't find solution. I tried something very simple but it doesn't work: show.html.erb &...
marcellobonini's user avatar
0 votes
3 answers
190 views

Determine if a time value exists in date/time string

I'm looking to write a method that will take a string and give me The datetime value if a time value is provided in the string The datetime value at the end of the day if only a date is provided in ...
David Ward's user avatar
0 votes
2 answers
33 views

Trying to find amount of Saturdays that fall on the last day of each month in Ruby

I am working on a very specific problem. I need to find the number of times that Saturday falls on the last day of each month within a five year time period. For this example, I need to find those ...
mandee_smith's user avatar
0 votes
3 answers
50 views

I am trying to subtract 3 hours from a method that I have created but I am getting an error

I have successfully created a DST method called dst_datechange that takes a date, is parsed out using Time.parse. It looks like this: require 'time' def dst_datechange(date) date = Time.parse(date....
AA.'s user avatar
  • 29
0 votes
2 answers
208 views

Format Date in Ruby

I have a date returned as a string: date_str = "2018-08-17" How would I format this in to another standard date format, eg. 17/08/2018 programatically without having to parse the string manually?
Ben Harvie's user avatar
0 votes
4 answers
568 views

Find out if current time is between two times

I have two time columns stored in a Postgresql database: open_time and close_time. I'm trying to find out if the current time, ignoring the date, is between the two times, ignoring the dates. This ...
NathanB's user avatar
  • 105
1 vote
4 answers
232 views

Ruby sort array of strings by time value in each string

I have an array of strings like this: strings = [ "ANT 107 90 Intro to Envrmntl Archaeology CMWL 101 TTH 01:00PM-02:15PM Markin 2/15 0 4.00", "AMS 210 10 Intro to ...
Lyres's user avatar
  • 341
0 votes
2 answers
3k views

Convert number to date in Ruby

I get a number representing date from a back-end, and I'm trying to convert it to a date this way: number = item["created"].to_i number #=> 1512387277084 DateTime.strptime(number.to_s ,'%s') #=>...
Rainmaker's user avatar
  • 11.2k
3 votes
1 answer
2k views

How to compare times in different time zones in Ruby?

I have this date that which is in timezone offset format that I need to convert to UTC format. For example: date1 = 2017-07-13T17:13:12-04:00 date2_utc = 2017-07-13 21:13:12 UTC I need to compare ...
KiranGautam's user avatar
1 vote
1 answer
1k views

How to parse date and time with Date.strptime

If I use Date#strptime to parse an Exif date like 2017:03:11 18:02:30 the time is ignored: Date.strptime("2017:03:11 18:02:30", '%Y:%m:%d %H:%M:%S').strftime('%Y:%m:%d %H:%M:%S') => "2017:03:11 ...
multiholle's user avatar
  • 3,170
0 votes
1 answer
4k views

ArgumentError: invalid strptime format - `%m/%d/%y' work around

I am in the process of working with an sftp import bug in which I'm trying to flag any dates that are imported that are incorrect. There are two types of dates that could be off. The first is when the ...
kdweber89's user avatar
  • 2,204
3 votes
5 answers
2k views

Ruby - how to find the NEXT occurrence of a given hour?

I want to return a Ruby Time object (miliseconds) that represents the next X hour from a given DateTime. Examples for the next 5am if it currently is 9pm on 3/28, the NEXT 5am would be 3/29 5am if it ...
james's user avatar
  • 4,047
-1 votes
2 answers
70 views

Compare approximately time and date in Ruby

I have 2 variables with Time and Date: var1 = "2017-03-24 10:37:59" var2 = "2017-03-24 10:38:12" I need to come up with algorithm to compare those 2 variables, but if difference of 2 minutes should ...
N N's user avatar
  • 1,638

15 30 50 per page
1
2 3 4 5
7