Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6071685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:04:32+00:00 2026-05-23T10:04:32+00:00

I need to store time inverval in PosgreSQL. Data will be put from Ruby

  • 0

I need to store time inverval in PosgreSQL. Data will be put from Ruby on Rails.

Say, PizzaHut accepts orders from 9:00 to 18:00.

I’ve created following migration:

class AddOrderTimeAndDeliveryTimeToMerchants < ActiveRecord::Migration
  def self.up
    add_column :merchants, :order_time, :interval
  end

I’ve read the documentation, and have following code now:

Merchant.create( :delivery_time => "9:00 18:00" )

When i execute it, i get following error message:

PGError: ERROR:  invalid input syntax for type interval: "9:00 18:00"

How to do it correctly ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:04:33+00:00Added an answer on May 23, 2026 at 10:04 am

    I don’t think an interval is really what you want for that. An interval represents a timespan without any specific end points; for example, you add an interval to an existing time to get another time. You would be better off with two distinct times:

    add_column :merchants, :order_from, :time, :null => false
    add_column :merchants, :order_to,   :time, :null => false
    

    Then, if for some reason you need to know how many hours they’re open for delivery, you can construct an interval by subtracting :order_from from :order_to.

    If you really must use an interval, then you’ll need to construct a value something like this:

    :delivery_time => "interval '11 hour'"
    

    Note how this illustrates that an interval is not a specific time range from A to B, it is just a time range of some certain length (with no specified end points).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store settings that update from time to time about my website
I need to store a time offset in a database column (for example, 12:25
I need to store the summer time (daylight saving time) change-over rules for different
I need to store items with a calendar date (just the day, no time)
I need to be able to store a date (year/month/day) with no time component.
I need to store app specific configuration in rails. But it has to be:
I need to store some sensitive data by encrypting it with atleast 128 bit
I need to store multi-dimensional data consisting of numbers in a manner thats easy
I want to store a time value and need to retrieve and edit it.
I have the need to capture a time and time zone from users of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.