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 8842011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:51:34+00:00 2026-06-14T10:51:34+00:00

Is there an easy way to do this? By fully between, I mean don’t

  • 0

Is there an easy way to do this? By fully between, I mean don’t count the 7am or 7pm datetimes that are equal to the start or end time.

I imagine this can be done using the unix timestamp in seconds and a bit of algebra, but I can’t figure it out.

I’m happy to use something in PLSQL or plain SQL.

Examples:

start             end               num_7am_7pm_between_dates
2012-06-16 05:00  2012-06-16 08:00  1  
2012-06-16 16:00  2012-06-16 20:00  1
2012-06-16 05:00  2012-06-16 07:00  0
2012-06-16 07:00  2012-06-16 19:00  0
2012-06-16 08:00  2012-06-16 15:00  0
2012-06-16 05:00  2012-06-16 19:01  2
2012-06-16 05:00  2012-06-18 20:00  6 
  • 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-06-14T10:51:35+00:00Added an answer on June 14, 2026 at 10:51 am

    I think this could be reduced further but I don’t have Oracle at my disposal to completely test this Oracle SQL:

    SELECT StartDate
         , EndDate
         , CASE WHEN TRUNC(EndDate) - TRUNC(StartDate) < 1
                 AND TO_CHAR(EndDate, 'HH24') > 19
                 AND TO_CHAR(StartDate, 'HH24') < 7
                THEN 2
                WHEN TRUNC(EndDate) - TRUNC(StartDate) < 1
                 AND (TO_CHAR(EndDate, 'HH24') > 19
                  OR  TO_CHAR(StartDate, 'HH24') < 7)
                THEN 1
                WHEN TRUNC(EndDate) - TRUNC(StartDate) > 0
                 AND TO_CHAR(EndDate, 'HH24') > 19
                 AND TO_CHAR(StartDate, 'HH24') < 7
                THEN 2 + ((TRUNC(EndDate) - TRUNC(StartDate)) * 2)
                WHEN TRUNC(EndDate) - TRUNC(StartDate) > 0
                 AND TO_CHAR(EndDate, 'HH24') > 19
                  OR TO_CHAR(StartDate, 'HH24') < 7
                THEN 1 + ((TRUNC(EndDate) - TRUNC(StartDate)) * 2)
                ELSE 0
           END
    FROM MyTable;
    

    Thanks to @A.B.Cade for the Fiddle, it looks like my CASE Logic can be condensed further to:

    SELECT SDate
         , EDate
         , CASE WHEN TO_CHAR(EDate, 'HH24') > 19
                 AND TO_CHAR(SDate, 'HH24') < 7
                THEN 2 + ((TRUNC(EDate) - TRUNC(SDate)) * 2)
                WHEN TO_CHAR(EDate, 'HH24') > 19
                  OR TO_CHAR(SDate, 'HH24') < 7
                THEN 1 + ((TRUNC(EDate) - TRUNC(SDate)) * 2)
                ELSE 0
           END AS MyCalc2
      FROM MyTable;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am hoping that there might be an easy way to do this, I
Is there an easy way to you this with the asset pipeline and deploying
Is there an easy/clean way to do this in Linux/ a Linux-like environment? Purpose
Is there an easy way to convert date and time like this: Sun, 14
I am sure there is no easy way to do this but I have
Is there an easy way to unroll the stack in Tcl? I have this
As a follow up to this question: Is there an easy way to pickle
Sorry if this is a stupid question, but is there an easy way to
Is there an easy (therefore quick) way to accomplish this? Basically just take some
Is there an easy way of preventing an accordion in JavaFX 2.1 from fully

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.