Dates that fall on weekday and weekend

Hi everyone, consider the following data i have.
WITH eff_dates AS
SELECT To_Date('1/29/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
SELECT To_Date('2/1/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
SELECT To_Date('2/3/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
SELECT To_Date('2/4/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
SELECT To_Date('2/26/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
SELECT To_Date('3/1/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
SELECT To_Date('3/31/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
SELECT To_Date('4/1/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
SELECT To_Date('4/30/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
SELECT To_Date('5/3/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
SELECT To_Date('5/4/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
SELECT To_Date('5/28/2010','mm/dd/yyyy') c_date FROM dual
output should be
C_DATE
1/29/2010
2/26/2010
3/31/2010
4/30/2010
5/28/2010this is how to get to this output.
i want to display all month end dates. you might already notice that 1/29 and 2/26 and 5/28 are not month end date. however, they fall on the last friday of the
month. so basically i want to display all month end dates that fall on a weekday and if they fall on a weekend, then display the date of the last friday for that
month
can somebody help write a query that produce the output above for the data given?

Try this:
SQL> WITH eff_dates AS
  2  (
  3  SELECT To_Date('1/29/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
  4  SELECT To_Date('2/1/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
  5  SELECT To_Date('2/3/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
  6  SELECT To_Date('2/4/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
  7  SELECT To_Date('2/26/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
  8  SELECT To_Date('3/1/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
  9  SELECT To_Date('3/29/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
10  SELECT To_Date('3/30/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
11  SELECT To_Date('3/31/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
12  SELECT To_Date('4/1/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
13  SELECT To_Date('4/30/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
14  SELECT To_Date('5/3/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
15  SELECT To_Date('5/4/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
16  SELECT To_Date('7/30/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
17  SELECT To_Date('8/27/2010','mm/dd/yyyy') c_date FROM dual UNION ALL
18  SELECT To_Date('5/28/2010','mm/dd/yyyy') c_date FROM dual
19  )
20  select c_date,
21         to_char(c_date, 'DY', 'NLS_DATE_LANGUAGE=ENGLISH') wd_c_date,
22         ld,
23         to_char(ld, 'DY', 'NLS_DATE_LANGUAGE=ENGLISH') wd_ld
24    from (select c_date, last_day(c_date) ld  from eff_dates)
25   where to_char(c_date, 'DY', 'NLS_DATE_LANGUAGE=ENGLISH') in ('MON', 'TUE', 'WED', 'THU', 'FRI')
26         and (c_date = ld or c_date = trunc(ld, 'iw') + 4);
C_DATE      WD_C_DATE LD          WD_LD
29/1/2010   FRI       31/1/2010   SUN
26/2/2010   FRI       28/2/2010   SUN
31/3/2010   WED       31/3/2010   WED
30/4/2010   FRI       30/4/2010   FRI
30/7/2010   FRI       31/7/2010   SAT
SQL> Except that in your sample output I think may 28 may have been a mistake, since may 31 is not on a weekend.

Similar Messages

  • Schedule on  diffirent  time for weekdays and weekends

    Hi,
    I need to schedule some job:
    for weekdays (from Monday to Friday) at 18:00
    for weekends (from Saturday to Sunday) at 13:00
    If it is possible to do that?
    I can schedule it from Monday to Sunday at 18:00 or from Monday to Sunday at 13:00. But my requirements are diffirent
    Thank you

    Yes, you must create two schedules and comine it together
    BEGIN
    dbms_scheduler.create_schedule('sch_1', repeat_interval => 'freq=daily;byday=MON,TUE,WED,THU,FRI;byhour=18;byminute=0;bysecond=0');
    dbms_scheduler.create_schedule('sch_2', repeat_interval => 'freq=daily;byday=SUN,SAT;byhour=13;byminute=0;bysecond=0');
    END;
    --test
    DECLARE
      start_date   TIMESTAMP;
      return_date_after TIMESTAMP;
      next_run_date        TIMESTAMP;
    BEGIN
      start_date := SYSDATE;
      return_date_after := start_date;
      FOR i IN 1..20 LOOP
        DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING('sch_1,sch_2',
        start_date, return_date_after, next_run_date);
        DBMS_OUTPUT.PUT_LINE('next_run_date: ' || next_run_date);
        return_date_after := next_run_date;
    END LOOP;
    END;
    /an result:
    next_run_date: 16.04.13 18:00:00,000000
    next_run_date: 17.04.13 18:00:00,000000
    next_run_date: 18.04.13 18:00:00,000000
    next_run_date: 19.04.13 18:00:00,000000
    next_run_date: 20.04.13 13:00:00,000000
    next_run_date: 21.04.13 13:00:00,000000
    next_run_date: 22.04.13 18:00:00,000000
    next_run_date: 23.04.13 18:00:00,000000
    next_run_date: 24.04.13 18:00:00,000000
    next_run_date: 25.04.13 18:00:00,000000
    next_run_date: 26.04.13 18:00:00,000000
    next_run_date: 27.04.13 13:00:00,000000
    next_run_date: 28.04.13 13:00:00,000000
    next_run_date: 29.04.13 18:00:00,000000
    next_run_date: 30.04.13 18:00:00,000000
    next_run_date: 01.05.13 18:00:00,000000
    next_run_date: 02.05.13 18:00:00,000000
    next_run_date: 03.05.13 18:00:00,000000
    next_run_date: 04.05.13 13:00:00,000000
    next_run_date: 05.05.13 13:00:00,000000

  • Constraint on a Date Column to Not Allow Setting Weekend Dates

    We are utilizing SQL Server 2008 R2 for scheduling AD user migrations. We keep track of all user accounts to be migrated and have a column for Migration_DATE with data type "Date". 
    I am looking to add a constraint to the Migration_DATE column to not allow scheduling dates on weekends. In other words I don't want anyone setting dates that fall on the weekend or a list of dates on a table.  Can anyone help me with how to do this
    or point me in the right direction. 
    Thanks much!

    Hello,
    Based on your description, you had a table which used for track AD user migration. And you wan to alter the date column "Migration_DATE" to not allow insert weekend date. If I understanding correctly, you can add a constraint to check the insert values.
    ALTER TABLE teble_name ADD constraint ck_Migration_date
    CHECK (DATENAME(WEEKDAY,Migration_DATE) NOT IN ('Saturday','Sunday'))
    Reference:Creating and Modifying CHECK Constraints
    Regards,
    Fanny Liu
    If you have any feedback on our support, please click here. 
    Fanny Liu
    TechNet Community Support

  • How do I look for a date that corresponds to a particular Week Number in a table?

    Hello,
    I have a table (Table A) that looks like this (I am only including the first 5 months to keep image size down):
    The numbers in the table are dates, with custom formatting to just show the day.
    I have another table with all of the Week Numbers for a given year in the first column and a second column in which I would like a formula to count the numbers of dates in Table A that correspond to the Week Number in the first column (i.e. the number of dates that falls within that week).
    The following statement works for testing single cells:
    =COUNTIF(WEEKNUM(Table A :: $Session 1 $January,2),A1)
    But it would seem that I can only use this with single cells and not the table as a whole.
    Could someone help with a solution to this?
    Thanks,
    Nick

    Thanks Jerry.  If I have understood you correctly I would need to calculate the week numbers of the dates in Table A in Table A itself, like this:
    Then I would use the COUNTIF function to test the array of week numbers in Table A.  If this is correct, I am not sure how to construct an array that includes just the cells with week numbers. I presume I could do this either manually or based on the value in the first column of Table A (i.e. just testing the five columns to the right of each "Week No" row), but I'm not sure.
    Nick

  • Create an absolute time display that can be paused and scrolled

    I have 3 waveform graphs that are scrolling by as the data is collected.  They represent past events that can be paused, scrolled back, and printed.  It represents 8 hours of data.  I do not have a time stamp associated with the data going into the graphs at this time.  I dont want to reinvent the Field Point code that is gathering the data just tweak the Host program that monitors the data (this would require flying to the customer site).  I need to have a absolute time clock that will keep up with the data that is scrollong by and pause when the graphs are paused (that is the easy part).  Here is my challenge.  I am using a property node from all three graphs.  I have the x scale-range-all elements tied together so they will all scroll together with 1 x scroll bar.  I need to be able scroll the absolute time clock with the other information.
    Any ideas?
    AUTOM8

    Hi,
    You can use the Get date/time function to get time when the data is recorded. However be advised that this time would only be close to the actual time of data acquisition.  It will not be the actual time when the data was acquired.
    As for scrolling the time display, I think yout best bet would be to tie in a  time stamp (Get date/time function ) with the Y values that you are already acquiring. Then when you scroll to a particular point in the graph, you can programmatically unbundle the waveform at that point to get the time value.
    Regards,
    Ankita

  • How do you remove back up data from the memory storage? my storage data states that i have over 80gb of data used for back ups and i dont know why as i use a external hard drive as a time machine .now my 250gb flash storage is nearly full

    how do you remove back up data from the memory storage? my storage data states that i have over 80gb of data used for back ups and i dont know why as i use a external hard drive as a time machine .now my 250gb flash storage is nearly full.. HELP!

    When Time Machine backs up a portable Mac, some of the free space will be used to make local snapshots, which are backup copies of recently deleted files. The space occupied by local snapshots is reported as available by the Finder, and should be considered as such. In the Storage display of System Information, local snapshots are shown as  Backups. The snapshots are automatically deleted when they expire or when free space falls below a certain level. You ordinarily don't need to, and should not, delete local snapshots yourself. If you followed bad advice to disable local snapshots by running a shell command, you may have ended up with a lot of data in the Other category. Ask for instructions in that case.
    See this support article for some simple ways to free up storage space.

  • Weekdays and dates

    hi all,
    i have the following two requirements. Please let me know if there are any function modules for the same.
    1) I have a From-Date and a To-Date. Within this interval i want to find all the nth days of week. for example for n = 2, i want the dates for all mondays within this period.
    2) again for the interval (from-to date) i want the dates on the nth weekdays. for example, for n = 4 and weekday = 2, then i want dates for all 4th mondays of month within the period.
    (of course this means that the period will span for more than one month for the second requirement while for the first it can span for more than one week)
    regards,
    PJ

    Hi,
    combine fm <b>WFCS_FCAL_WDAYS_GET_S</b> (get workdays)
    and  fm <b>DAY_IN_WEEK</b> (nr. of the day)
    Andreas

  • Req. deliv.date should exclude holidays and weekends

    Hi guy,
    When I try to create my sales order. The Req.deliv.date and First date will automatically fill with date. The question is it should exclude weekends and holiday, but the result is not. Just like that
    The 07/12/2014 is Saturday. How should I make it automatically exclude weekends? Thank you in advanced.
    Best,
    Peter

    Hi Peter,
    The requested delivery date is the date that the customer is requesting the material arrive at their site. Therefore, the logical calendar to check this against is the unloading point calendar of the customer. Please maintain an unloading point and assign a calendar for the customer in transaction VD02.
    When you do this, the system will issue a warning of you enter a non-working day. There is not possibility to change this to an error in the standard system. The system assumes that the user knows what they are doing and takes priority over the warning message. However, the warning message does inform the user of the next working day.
    I remember replying to a similar thread about this before. You can find it here:
    No Schedule Line Dates on Weekends

  • Getting the next valid date (jump holidays and weekends)

    Hello,
    I have a column table where I have all holidays of the year in the format "yyyymmdd,yyyymmdd,...", for example, "20091012,20091225".
    I'd like to do a query where I pass a date and a increment of days and it returns the next valid date, excluding weekends and the holidays that I have in the column holidays that I show above.
    P.S: Instead of pass a date and a increment of days, I could pass just a already incremented date, and this query just validate this date, adding 2 days for each weekend and one day for each holiday.
    Is there a way to do that?
    Thanks

    Hi,
    Ranieri wrote:
    Hello,
    I have a column table where I have all holidays of the year in the format "yyyymmdd,yyyymmdd,...", for example, "20091012,20091225".Dates should always be stored in DATE columns. If you really want to, your can also store the formatted date in a separate column.
    I'd like to do a query where I pass a date and a increment of days and it returns the next valid date, excluding weekends and the holidays that I have in the column holidays that I show above.For convenience, you can't beat a user-defined function, such as Etbin's.
    If you really want a pure SQL solution, you can
    (a) generate a list of all the days that might be between the start date and end date (sub-query all_days below)
    (b) outer join that to your holiday table (sub-query got_dnum, below)
    (c) rule out the holidays and weekends (sub_query got_dnum, WHERE clause)
    (d) return the nth remaining day (main query below)
    WITH     all_days     AS
         SELECT  TO_DATE (:start_date, 'DD-Mon-YYYY') + LEVEL     AS dt
         FROM     dual
         CONNECT BY     LEVEL <= 3           -- 3 = max. consecutive non-work days
                   + (:day_cnt * 7 / 4)     -- 4 = min. work days per week
    ,     got_dnum     AS
         SELECT     a.dt
         ,     ROW_NUMBER () OVER (ORDER BY a.dt)     AS dnum
         FROM          all_days     a
         LEFT OUTER JOIN     holidays     h     ON     a.dt = TO_DATE (txt, 'YYYYMMDD')
         WHERE     h.txt               IS NULL
         AND     TO_CHAR (a.dt, 'Dy')      NOT IN ('Sat', 'Sun')
    SELECT     dt
    FROM     got_dnum
    WHERE     dnum     = :day_cnt
    ;This assumes :day_cnt > 0.
    The tricky part is estimating how far you might have to go in sub-query all-days to be certain you've included at leas :day_cnt work days.
    Where I work, holidays are always at least 7 days apart.
    That means that there can be, at most, 3 consective days without work (which happens when there is a holiday on Monday or Friday), and that thee are at least 4 work days in any period of 7 consecutive days. That's where the "magic numbers" 3 and 4 come from in the CONNECT BY clause of all_days. Depending on your holidays, you may need to change those numbers.
    P.S: Instead of pass a date and a increment of days, I could pass just a already incremented date, and this query just validate this date, adding 2 days for each weekend and one day for each holiday.Good thought, but it won't quite work. How do you know how many holidays were in the interval? And what if the first step produces a Saturday before a Monday holioday?
    You might be interested in [this thread|http://forums.oracle.com/forums/message.jspa?messageID=3350877#3350877]. Among other things, it includes a function for determining if a given date (in any year) is a holiday, without reference to a table.

  • My Mac has broken and I want to sell it for parts. How can I be sure that my personal data that is/was on the hard drive is safe?

    My 2006 MacBook Pro has broken. There is a little bit of drive noise when I turn it on, but then nothing happens. It is no big deal. Most of my files were backed up. There are a few files I would like to recover if possible, but nothing worth a major effort.
    I have seen that broken MacBook Pro's go for about $300 on eBay for parts, so I would like to sell the MacBook Pro. However, I only want to do that after I am sure that my personal data is wiped out. Does anyone know how I can accomplish that? Does anyone know of an easy way to search the old hard drive for some of the data that I lost? Can a Genius Bar take care of this stuff for me (and how much do they charge?)?
    Thank you for your help.
    - Eric

    EricNY wrote:
    I only want to do that after I am sure that my personal data is wiped out. Does anyone know how I can accomplish that?
    The ONLY real secure way to be sure that noone may recover data from your drive is, to remove the drive, and drill one or two 1" holes thru the disk.
    A bit less secure but useful way is, to wipe out the data with a tool that's overwrite all sectors of the drive with randomized data in multiple runs.
    For example: Permanent Ereaser http://www.edenwaith.com/products/permanent%20eraser/
    Independent tests bring out, that even specialized recovery companies with forensic tools are unable to find useful data after such a run.
    EricNY wrote:
    Does anyone know of an easy way to search the old hard drive for some of the data that I lost?
    There are some recovery tools out there to fit your needs, e.g. MacKeeper http://mackeeper.zeobit.com/mac-data-recovery
    Lupunus

  • HT4847 I backed up my iphone 2 days ago via icloud. I now have restored my iphone to the factory settings and I need to retrieve the data that I backed up 2 days ago from icloud. My phone is only giving me an option to back up from my ipad icloud. Please

    Please Help
    I had lost all the music on my iphone a while back and wanted to put it back on but my PC is a dinosaur and couldn't handle the sync without taking days. I decided to give it a go anyway. I tried to sync but kept getting an error message saying "waiting for changes to be applied". I looked up a solution to this problem and I saw that I should restore the phone to factory settings which I did. I then tried to sync again and it worked! .....the downside was that it took forever and I was without a phone for 36 hrs while I waited for sync to complete. It was at 662 0f 771 last night when I went to bed and when I awoke this morn, syncing had ceased and my phone was still erased of all data.
    I am thinking now that everything was done and all I needed to do was turn off my phone and turn back on again but in a panic I selected an option on the phone to back up from icloud (as I knew I had done a backup 2 days ago). The only option available was "ipad backup" from over a week ago and stupidly I selected this option. It was successful but my contacts, mail, messages, photos and most importantly my notes and reminders are gone!!!
    I have now restored the phone back to factory settings again.
    WHAT DO I DO NEXT??

    I went back to iOS 7 and my backup file is restoring but when its done nothing is on my phone still and only takes 11-15 minutes to restore the backup instead of taking 25+ minutes like usual so I guess the backup is corrupted. How can I fix this?

  • Running a Sub-VI and monitoring data that is generated on a higher level VI

    Hi All, 
    This question must been there before, but I cannot find a suitable answer here on the forums....
    I have a 'top-level' VI that does a lot of things. I also have a sub VI that runs a frequency sweep on a piece of equipment. This is done with a for loop. 
    Problem: 
    I want to monitor/access the data that is generated in the for loop (See attached, the 3 wires within the green circle I want to monitor). 
    2 Questions:
    How can I access the data on the wires (within the loop) from a higher level VI?
    How can I then run this VI in a higher level VI while the higher level VI is continuing and not waiting for the sub-VI to complete?
    I tried using a Que but I cannot seem to get that working. 
    Any suggestions?
    Regards,
    Attachments:
    LV problem.PNG ‏44 KB

    The queue is a good way to move data from a running subVI to another VI.  Your problem is that if the subVI is inside a loop in the main VI, that loop in the main VI cannot iterate until the subVI completes. The solution: have the sub VI running in parallel - not inside - the loop.
    Look at the Producer/Consumer Design Patterns (at File >> New... >> VI >> From Template >> Frameworks >> Design Patterns >> Producer/Consumer.  This may be more than you need at the moment but will show how the parallel code process works.
    Lynn

  • Hi, I am using HP11 and iPlanet web server. When trying to upload files over HTTP using FORM ENCTYPE="multipart/form-data" that are bigger than a few Kilobytes i get a 408 error. (client timeout).

    Hi, I am using HP11 and iPlanet web server. When trying to upload files over HTTP using FORM ENCTYPE="multipart/form-data" that are bigger than a few Kilobytes i get a 408 error. (client timeout). It is as if the server has decided that the client has timed out during the file upload. The default setting is 30 seconds for AcceptTimeout in the magnus.conf file. This should be ample to get the file across, even increasing this to 2 minutes just produces the same error after 2 minutes. Any help appreciated. Apologies if this is not the correct forum for this, I couldn't see one for iPlanet and Web, many thanks, Kieran.

    Hi,
    You didnt mention which version of IWS. follow these steps.
    (1)Goto Web Server Administration Server, select the server you want to manage.
    (2)Select Preference >> Perfomance Tuning.
    (3)set HTTP Persistent Connection Timeout to your choice (eg 180 sec for three minutes)
    (4) Apply changes and restart the server.
    *Setting the timeout to a lower value, however, may    prevent the transfer of large files as timeout does not refer to the time that the connection has been idle. For example, if you are using a 2400 baud modem, and the request timeout is set to 180 seconds, then the maximum file size that can be transferred before   the connection is closed is 432000 bits (2400 multiplied by 180)
    Regards
    T.Raghulan
    [email protected]

  • My iPhone 5s on ios 8.1.2 is stuck at Apple logo or recovery mode.. To fix this issue, i need to update it to ios 8.2 through itunes.. I want to ask that my data i.e. Photos and other personal data would be removed after updating it or not..?

    My iPhone 5s on ios 8.1.2 is stuck at Apple logo or recovery mode.. To fix this issue, i need to update it to ios 8.2 through itunes.. I want to ask that my data i.e. Photos and other personal data would be removed after updating it or not..?
    if yes then how can i save my data or get out of recovery mode.. Is there any safe mode or something like that on which i could access my data..
    P.S. I have not taken any backup of my iPhone on itunes..
    Please help me sort out this issue..

    Recovery mode doesn't mean that all your data is already lost. You only lose your data if you restore it.
    When you plug the phone is into iTunes hold down the home button. iTunes may then give you the option JUST to update the software first. This should not get rid of any data.
    However, if iTunes is only giving you the option to RESTORE and update, then you will lose your data I'm afraid.
    Hope that helps!

  • How do I restore my itunes library? My computer was restored to factory settings and I couldn't find a restore date that allowed my to get access to all of my files. Now my itunes library is empty minus the songs we've recently purchsed!

    MY computer was restored to factory settings. Is there a way to get my previous itunes library back? I don't have an Ipod or other device that I saved my itunes library to.

    Restore the media from the backup of the computer.
    If it was simply restored via the Windows restore point, no data on the computer should have been affected.
    If the computer was formated and Windows re-installed, no data remained on the computer and will have to be added back by the user.

Maybe you are looking for

  • Sleep Issues with Macbook Pro

    Hi all, When I wake my laptop (15" Spring 2011 Macbook Pro) while it's connected to a power source, I see the screen for a split second before it goes black. Nothing I do will make the screen come back until I disconnect the power source, at which po

  • Oracle process running out of OS kernel I/O resources

    Hi All, Here is our platform: Oracle Version: 10.2.0.4.0 O/S: Linux x86_64 We are getting the below Error Msg: ERROR: =================================================================== WARNING:io_submit failed due to kernel limitations MAXAIO for pr

  • Delta on Customized Data Source

    Hi all, Our requirement is we want to make one customized data source as delta enable. First is it possible? please give me some document or share real experience so that it will be easy to explain to the peoples out here. I need a detailed explanati

  • User roles and role mapping

    I've just start as an intern in Change Management team that is helping to implement SD. My two tasks are to "develop SAP user roles specific to the new business processes" and "manage the role to position mapping for provision of security roles." Non

  • Is the trial version reflective of the real application?

    I have downlaoded the trail version and find that the application is VERY SLOW at undertaking commands and not in the same league as the speed of Excel for Mac. Is the poor response time I am experiencing (major) because I am don't have an Intel proc