convert time DD:hh:mm:ss format into seconds in Rails 3
I need to get time value of DD:hh:mm:ss into seconds. Value is an output
from a postgresql db query and looks something like this:
db_value = '456:14:56:10'
and I need to get it into seconds, I have an method in my application
which does vice versa like this:
def time_converter(seconds)
days = seconds / 86400
seconds -= days * 86400
hours = seconds / 3600
seconds -= hours * 3600
minutes = seconds / 60
seconds -= minutes * 60
return "#{days}:#{hours}:#{minutes}:#{seconds}"
Can I use this method somehow or is it possible to change format in
postgresql into seconds? What is the most efficient way of doing it?
db value is part of a SUM((end_time - start_time)* multiplier) AS duration
query.
No comments:
Post a Comment