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

  • SEARCH
  • Home
  • 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 7083071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:07:59+00:00 2026-05-28T07:07:59+00:00

Let’s say I’m maintaining a database of events, which could be anything from the

  • 0

Let’s say I’m maintaining a database of events, which could be anything from the weekly schedule of a business’s operating hours (Monday-Friday: 10AM-7PM, Sat: 12PM-6PM, Sun: Closed) to monthly events (Art fair, every first Saturday, from 10AM – 5PM) to an annual event (Christmas Eve charity dinner, 7PM-9PM)

In an ideal situation, I would like to query the database with any given day, say:
Thursday, Jan. 12, 2012, 12PM

…and find all events that are occurring on:

  • a regular Thursday noon (such as a business being open)
  • every second Thursday (an art fair)
  • Jan. 12, specifically (er…Turkmenistan Memorial Day)

I suppose there’s no point in talking about the query construction without first thinking how such dates/times would be stored in a database.

I can’t think of how the concept of regular weekly operating hours (even ignoring edge cases) could be modeled in a one-record, single field that would also model a once-every-year event. At the very least, it seems like I would need at least five fields:

  • Start-time
  • Duration
  • Day of the week (e.g. Mon. Tues., etc)
  • optional absolute annual date (e.g. May 8)
  • optional monthly occurrence (fourth Wednesdays)

And I’m guessing there’s no way to encapsulate this in a single row, right? For example, a business open every weekday would have five records.

And the end goal is to be able to do a relatively elegant query that could find all event-records which contain a given moment in their timeframe.

  • 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-28T07:07:59+00:00Added an answer on May 28, 2026 at 7:07 am

    Not sure if you are asking specifically for a dbms-agnostic solution, anyway in postgresql (and I think it’s possible in most RDBMS) you can store Timestamps and get a lot of info out of them: http://www.postgresql.org/docs/8.4/interactive/functions-datetime.html.

    Postgresql-specific answer

    9.9.1. EXTRACT, date_part

    EXTRACT(field FROM source) The extract function retrieves subfields
    such as year or hour from date/time values. source must be a value
    expression of type timestamp, time, or interval. (Expressions of type
    date are cast to timestamp and can therefore be used as well.) field
    is an identifier or string that selects what field to extract from the
    source value. The extract function returns values of type double
    precision. The following are valid field names: […] day, DOW (day of week), DOY (day of year), […]

    So for instance, to select events occurring each 2nd Thursday you could write:

    SELECT * FROM events  #your table
        WHERE EXTRACT(DOW FROM date_column)=4 # DOW  goes from sunday (0) to saturday (6)
        AND EXTRACT(DAY FROM date_column)>7 # must occurr after 7th day of the month (ie. if the 1st is a Thursday
        AND EXTRACT(DAY FROM date_column)<15 # and before the 15th (ie. if the 1st is a Friday, so the first Thursday is on the 7th, and the second is on the 14th)
    

    To model duration you may simply have 2 timestamp fields, for the start/end of the event.

    Also note that you can add or subtract timestamps, as well as know if intervals overlap.

    In general, I would first try to use datatypes and functions provided by your DBMS, and only if you cannot really find a solution try to model it yourself.

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

Sidebar

Related Questions

Let's say I have a method in java, which looks up a user in
Let's say that I have a SQLite database that I create in a separate
Let's say I'm making a tool to help epicureans keep track of which delicacies
Let's say an operating system is installed on a computer and a DBMS is
Let's say I have the string: hello world; some random text; foo; How could
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say I have a dataset, which can be neatly classified using weka's J48
Let's say I'm writing a Windows Forms (.NET Framework 3.5) application which shows the
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say users can choose any amount of numbers from a list of 1

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.