2

how to get only time without date ruby + sequel for type time in MYSQL? ruby adding extra date '2000-01-01' with time for column type 'time' in MySQL. if the time '00:01:01' then ruby giving '2000-01-01 00:01:01 +530' in response with sequel.

Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20
Dileep Nunna
  • 117
  • 3
  • 11
  • Can you post your code showing how you're accessing the data? – RossMc Oct 26 '15 at 09:01
  • response = databasename.where([Sequel.qualify(:portalcdrs, :start_time) > starttime], Sequel.qualify(:portalcdrs, :end_time) < endtime, :flowid => flowid).all.map { |h| h.values } – Dileep Nunna Oct 26 '15 at 09:02

1 Answers1

0

You can't specifically choose to just retrieve the time from this object, but you You can use DateTime#strftime to just display the values you need.

>> t = Time.now
=> 2015-10-26 09:08:31 +0000

>> t.strftime("%H:%M:%S")
=> "09:08:31"

It doesn't look like you can eliminate the date element due to the way Ruby deals with time, see here.

Community
  • 1
  • 1
RossMc
  • 426
  • 2
  • 6
  • but the column type in mysql is only time and the value is '00:00:08'. why it is showing with date like '2000-01-01 00:01:08 +530'. how to t.strftime in sequel response for all columns? – Dileep Nunna Oct 26 '15 at 09:12
  • Do you have the details of the table and columns? – RossMc Oct 26 '15 at 09:22
  • yes, there is duration column with type 'time' in mysql. i want to apply strftime for all columns. – Dileep Nunna Oct 26 '15 at 09:41
  • my query is 'esponse = databasename.where([Sequel.qualify(:portalcdrs, :start_time) > starttime], Sequel.qualify(:portalcdrs, :end_time) < endtime, :flowid => flowid).all.map { |h| h.values }'. how to apply strftime for duration column. – Dileep Nunna Oct 26 '15 at 11:35
  • result.each { |x| x[:coulmn_name] = x[:column_name].to_f } – Dileep Nunna Oct 27 '15 at 05:57