Solved

Oracle Weekends only from the last 6 months onwards

Posted on 2011-02-28
5
465 Views
Last Modified: 2012-05-11
Let's say I have a table that has 2 coloumns:

TicketNumber
DateOpened - (YYYY-MM-DD HH24:MI:SS format)

I would like to get only the tickets opened during the weekends (From Friday at 19:00:00 to Monday at 07:00:00) from 6 months ago up to the last weekend. this would be ran every monday morning at 7:30am

what would be the optimized way of doing this?

thanks!
0
Comment
Question by:lemmohr
  • 4
5 Comments
 
LVL 73

Expert Comment

by:sdstuber
ID: 34997993
DateOpened - (YYYY-MM-DD HH24:MI:SS format)


does that mean dateopened is actually a string type rather than a date type

or just that you prefer to see date types converted to strings in that format?
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 34998031
assuming it really is a date then...



SELECT *
  FROM yourtable
 WHERE (TO_CHAR(dateopened, 'Dy') = 'Fri' AND dateopened >= TRUNC(dateopened) + 19 / 24)
       OR (TO_CHAR(dateopened, 'Dy') = 'Mon' AND dateopened <= TRUNC(dateopened) + 7 / 24)
       OR (TO_CHAR(dateopened, 'Dy') IN ('Sat', 'Sun'))
          AND dateopened >= ADD_MONTHS(TRUNC(SYSDATE, 'mm') - 6)
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 34998045
if it is a string type then, do the same thing, but convert it to a date first


SELECT *
  FROM yourtable
 WHERE (TO_CHAR(TO_DATE(dateopened, 'yyyy-mm-dd hh24:mi:ss'), 'Dy') = 'Fri'
        AND TO_DATE(dateopened, 'yyyy-mm-dd hh24:mi:ss') >=
                TRUNC(TO_DATE(dateopened, 'yyyy-mm-dd hh24:mi:ss')) + 19 / 24)
       OR (TO_CHAR(TO_DATE(dateopened, 'yyyy-mm-dd hh24:mi:ss'), 'Dy') = 'Mon'
           AND TO_DATE(dateopened, 'yyyy-mm-dd hh24:mi:ss') <=
                   TRUNC(TO_DATE(dateopened, 'yyyy-mm-dd hh24:mi:ss')) + 7 / 24)
       OR (TO_CHAR(TO_DATE(dateopened, 'yyyy-mm-dd hh24:mi:ss'), 'Dy') IN ('Sat', 'Sun'))
          AND TO_DATE(dateopened, 'yyyy-mm-dd hh24:mi:ss') >= ADD_MONTHS(TRUNC(SYSDATE, 'mm') - 6)
0
 

Author Closing Comment

by:lemmohr
ID: 34998875
this is perfect, i forgot to mention that it is a date type
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 34998887
glad I could help,  remember  dates don't have formats.

Only strings do
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
one-way data "masking" MD5 sql 26 104
sql query 5 52
query in Oracle forms Builder 2 27
Maintaining Oracle Managed Accounts 2 21
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now