Find last Tuesday

Hello

I have a requirement where I need to calculate the date of last Tuesday.

For example, consider table below.

January 12, 16Tuesday
January 13, 16Wednesday
January 14, 16Thursday
January 15, 16Friday
16 January 16Saturday
17 January 16Sunday
18 January 16Monday
19 January 16Tuesday
20 January 16Wednesday
21 January 16Thursday
22 January 16Friday
23 January 16Saturday
24 January 16Sunday
25 January 16Monday

f I am executing query on 15 Jan, Jan 18 or 19 January 16, it should return me January 12, 16.

If I spend 25 January 16, January 21, 16 it should return me January 19, 16.

He would do any date format.

Experts can you please provide information how do I train for this select statement?

Kind regards

Mahesh

Or, regardless of the NLS settings...

SQL > with dt as (select to_date('&date','DD-MM-YYYY') as double dt)
2,dow as (select 1 + trunc (dt) - trunc(dt,'IW') as dow of dt)
3 select dt, dt + mod (-(dow + 5 + Etui quand dow > = 3 then fin 1 0 sinon), 8) as last_tuesday
4 DT cross join dow
5.
Enter the value of date: 01/12/2016
old 1: with dt as (select to_date('&date','DD-MM-YYYY') as double dt)
new 1: with dt as (select to_date('12-01-2016','DD-MM-YYYY') as double dt)

LAST_TUESDAY DT
-------------------- --------------------
12 JANUARY 2016 00:00:00 JANUARY 5, 2016 00:00:00

SQL > /.
Enter the value of date: 13/01/2016
old 1: with dt as (select to_date('&date','DD-MM-YYYY') as double dt)
new 1: with dt as (select to_date('13-01-2016','DD-MM-YYYY') as double dt)

LAST_TUESDAY DT
-------------------- --------------------
13 JANUARY 2016 00:00:00 JANUARY 12, 2016 00:00:00

SQL > /.
Enter the value of date: 18/01/2016
old 1: with dt as (select to_date('&date','DD-MM-YYYY') as double dt)
new 1: with dt as (select to_date('18-01-2016','DD-MM-YYYY') as double dt)

LAST_TUESDAY DT
-------------------- --------------------
18 JANUARY 2016 00:00:00 JANUARY 12, 2016 00:00:00

SQL > /.
Enter the value of date: 19/01/2016
old 1: with dt as (select to_date('&date','DD-MM-YYYY') as double dt)
new 1: with dt as (select to_date('19-01-2016','DD-MM-YYYY') as double dt)

LAST_TUESDAY DT
-------------------- --------------------
19 JANUARY 2016 00:00:00 JANUARY 12, 2016 00:00:00

SQL > /.
Enter the date value: 20/01/2016
old 1: with dt as (select to_date('&date','DD-MM-YYYY') as double dt)
new 1: with dt as (select to_date('20-01-2016','DD-MM-YYYY') as double dt)

LAST_TUESDAY DT
-------------------- --------------------
JANUARY 20, 2016 00:00:00 JANUARY 19, 2016 00:00:00

Tags: Database

Similar Questions

  • find last Monday and Thursday of the year

    I use trunc (somedate, 'iyyy') to get the first Monday of the year, but have read messages that suggest that gives you the closest to the beginning of the year Monday.

    I need to find the last Monday of the year and also the last Thursday of the year. If the beginning of the year falls on Monday or Thursday, respectively, at the beginning of the year is what I need.

    I did extensive testing, but I think that these might get you what you want:

    NEXT_DAY(TRUNC(SYSDATE,'YEAR')-7,'THURSDAY')
    

    and

    NEXT_DAY(TRUNC(SYSDATE,'YEAR')-7,'MONDAY')
    

    Thursday is the first day of the year in 2009/2015, and Monday is the first day of the year in 2018.

    Sample:

    SQL> edit
    Wrote file sqlplus_buffer.sql
    
      1  SELECT  NEXT_DAY(TRUNC(SYSDATE,'YEAR')-7,'THURSDAY')    LAST_THURSDAY
      2  ,       NEXT_DAY(TRUNC(SYSDATE,'YEAR')-7,'MONDAY')      LAST_MONDAY
      3* FROM DUAL
    SQL> /
    
    LAST_THURSDAY       LAST_MONDAY
    ------------------- -------------------
    01/01/2009 00:00:00 12/29/2008 00:00:00
    

    Published by: Centinul on December 28, 2009 12:20

  • Finder last logon does not work on El captain

    Hi all

    I have problems with my Finder since El captain.

    It allows to view spreadsheets open past very well but now it seems selective in what it shows. I can open something and it will be displayed and if I open another file in a different folder, it will not show. Always on the same connection always on mac even still in the same session.

    Someone at - it ideas why it should be selective now when it used to work ok? I have not moved any of these files so nothing has changed except the version of the operating system.

    Any help would be appreciated.

    I realized I posted this in the wrong place I have an iMac, but I don't know how to move the pole. My apologies, but any help would be appreciated.

  • Find last record in a table

    Dear all,

    I have a table where each employee has information of promotion. I need every employee last promotion of information using sql

    Example of

    EmpID activedate

    -----          --------------

    100959 1/1/2014

    100959 6/1/2013

    100493 5/1/2014

    100493 12/1 / 2011

    the output will be

    EmpID activedate

    -----          --------------

    100959 1/1/2014

    100493 5/1/2014

    Hello

    Sanjay kumar roy wrote:

    Dear Frank,

    Thanks for your reply. But I need every wise employee his activedate above.

    as

    EmpID activedate

    -----          --------------

    100959 1/1/2014

    100959 6/1/2013

    100493 5/1/2014

    100493 12/1 / 2011

    the output will be

    EmpID activedate

    -----          --------------

    100959 1/1/2014

    100493 5/1/2014

    Then add a PARTITION BY clause to the RANK function.  For example:

    WITH got_rnk AS

    (

    SELECT emp. *- or everything you want columns

    Rank () OVER ( PARTITION BY deptno

    ORDER BY hiredate DESC

    ) AS rnk

    FROM scott.emp

    )

    SELECT *- or the list of all columns except rnk

    OF got_rnk

    WHERE rnk = 1

    ;

    I hope that answers your question.

    If not, post CREATE TABLE and INSERT statements for your sample data and your request.

    Specify where this query gets incorrect results and explain how get you good results in these places.

  • Oracle query: find last day of February

    Hello

    I'm struggling with a query that will return the last day of the previous/current February
    for example. If I run the query between February and December 2008, it should return February 29, 2008. If I run it in January 2009, it should always return February 29, 2008. If running between February and December 2009, it should return February 28, 2009

    Thanks in advance
    SQL> SELECT ADD_MONTHS(TRUNC(TO_DATE('20080620', 'YYYYMMDD'), 'YYYY'), 2)-1 FROM
     dual;
    
    ADD_MONT
    --------
    08/02/29
    
    SQL> SELECT ADD_MONTHS(TRUNC(TO_DATE('20090620', 'YYYYMMDD'), 'YYYY'), 2)-1 FROM
     dual;
    
    ADD_MONT
    --------
    09/02/28
    
    SQL>
    
  • Vista crashes frequently after the update of last Tuesday (May 8, 2012).

    My Vista computer has been completely stable for several years until that I installed the latest update. Now it's the gel with an disk activity but the cursor is frozen and the Task Manager are not available. Once it bombed just completely and the hard drive must be recovered.  Any ideas on what could be wrong and how to fix it.

    The problem now seems to have resolved itself.  We checked the newspapers anti-virus (avast!) and there was a huge spike in activity when problems are happening.

    I noticed that when avast! is active, it picks up the computer for a while - with the mouse, the keyboard and the Task Manager refused to function.

    Usually, it's only for a few moments, is not a problem.

    There was a continuous activity of avast! After that the Windows updates were first applied. The symptoms were exactly like the momentary avast! I have known "purchases" from time to time. They were only minutes not moments. These are the problems that I have for the first time.

    The disc has been restored. Updates reinstalled without problem and the computer is now back to normal.  Thanks for looking into this and for your advice.

  • Error when you try to find for Windows updates now?

    Is anyone else having problems with WU right now? I get this error message:

    "The website has encountered a problem and cannot display the page you are trying to view. The options provided below may help you solve the problem.
    For self-help options:

    Frequently asked Questions

    Find Solutions

    Windows Update Newsgroup
    To support options:

    Online Microsoft assisted support (no-cost for Windows Update issues)
     
    Learn more about the steps to take to fix this problem (error 0x8024402C number) yourself. »

    http://pastebin.ca/1914907 for my WindowsUpdate.log with newspapers when I try to find updates. I had no problem with OOTB last Tuesday update!

    Thank you in advance. :(

    Ant @ Ant links fed quality (http://aqfl.net) and The Ant Farm (http://antfarm.ma.cx).

    I had solved it. Apparently, you can't block svchost.exe. :( Ant @ Ant links fed quality (http://aqfl.net) and The Ant Farm (http://antfarm.ma.cx).

  • last working day of each week

    Hello world
    Could someone suggest how to configure Oracle 11g Scheduler so that it would start the last working day of each week? The last business day of the week is not always Friday; exceptional days are configured in separate planners, who are included or excluded in clause repeat_interval, (for example).

    The last business day of each month, works well, like this:

    BEGIN
    DBMS_SCHEDULER. () CREATE_SCHEDULE
    schedule_name = > "LAST_SETT_DAY_OF_MONTH"
    repeat_interval = > ' FREQ = MONTHLY; BYHOUR = 18; BYMINUTE = 30; BYDAY IS MON, MAR, SEA, GAME, FRI.; BYSETPOS =-1; EXCLUDE = HOLIDAY; INCLUDE = EXCEPTIONAL_WORKING_DAYS; ") ;
    END;

    But I want to run a similar logic for weeks.

    Thanks in advance

    OK, now I understand your request.
    I think it might be possible for PL/SQL function.
    Create the table suite where you put your nonworking days and the additional working days. To create the PL/SQL function and use

    CREATE TABLE day_list(
    DAY DATE NOT NULL,
    TYPE NUMBER(1) NOT NULL,
    CONSTRAINT pk_day_list PRIMARY KEY(DAY),
    CONSTRAINT ch_day_list_type CHECK(TYPE IN (1,2)));
    -- type 1-nonworking day,2-extra working day
    
    CREATE OR REPLACE FUNCTION last_working_day(p_date IN DATE) RETURN DATE AS
      v_retval DATE := TRUNC(p_date);
      v_aux    DATE;
    BEGIN
      IF v_retval IS NOT NULL
      THEN
        -- get next friday
        dbms_scheduler.evaluate_calendar_string(calendar_string => 'FREQ=DAILY; BYDAY=FRI',start_date => v_retval,return_date_after => v_retval,next_run_date => v_retval);
        -- check if SUNDAY or SATURDAY is extra working day
        SELECT MAX(DAY)
        INTO   v_aux
        FROM day_list
        WHERE TYPE=2
        AND DAY BETWEEN v_retval+1 AND v_retval+2;
        IF v_aux IS NOT NULL
        THEN
          v_retval := v_aux;
        ELSE
          -- find last working day from monday to friday
          WITH v_1 AS (SELECT v_retval - LEVEL +1 AS DAY
                         FROM dual
                         CONNECT BY LEVEL <=5)
          SELECT MAX(DAY)
          INTO   v_aux
          FROM (SELECT v_1.day, CASE WHEN t.type=1 THEN 0 ELSE 1 END is_working_day
                FROM v_1
                LEFT JOIN day_list t ON v_1.day=t.day AND t.type=1
                )
          WHERE is_working_day=1;
          -- there is a working day
          IF v_aux IS NOT NULL
          THEN
            v_retval := v_aux;
          ELSE
            -- go to next week
            v_retval := last_working_day(v_retval);
          END IF;
        END IF;
      END IF;
      RETURN v_retval;
    END;
    /  
    
  • PDF Acroform Javascript (WIN): Calculate the Date of next Tuesday

    03/06/10

    Greetings;

    I found a javascript script that will calculate the date of next Tuesday, but I can't seem to make it work in Acrobat Pro v8 (Acroforms).

    Any help / guidance you can provide is appreciated the most.

    Script:

    http://Christian.lassem.com/js/JavaScript-next-Tuesday/

    JavaScript to find next Tuesday?


    function find_date_of_next_tuesday() {}
    var today = new Date();
    today.setDate (today.getDate () + 1);
    While (today.getDay ()! = 2) {}
    today.setDate (today.getDate () + 1);
    }
    return (today.toDateString ());
    }

    Thanks in advance.

    You just need to call this function, and then use the string that it returns. What

    does not work, exactly?

  • Satellite A100 WIndows XP SP3 - Corrupted registry?

    Toshiba Satellite A100 WIndows XP SP3.

    A few days ago I noticed that windows update has stopped working and I had network problems. New research has shown that the BITS service did not start and other services such as DCOM did not begin. Fix - It of MS failed with the error code 7255. I tracked the issue to a possible Trojan horse as the registry keys had been renamed % fystemroot %. I've edited the keys to any %, according to online tips and delivered to market successfully. This has not fixed the BITS issue but more googling suggested that I needed a parameters key that included the Systemdll=%systemroot%\windows32\qmgr.dll value in the BIT key in HKLM system.

    I added this, but now when machine re boots I get a partial screen, no task bar, I can perform certain tasks by CTRL-ALT-DEL and the functioning of the Task Manager. I tried to cancel the changes by running regedit, but it does not work. None of the user accounts, even in the CMD has access to most of the services or the directories.

    I have the Toshiba repair disk but it seems to want to do a complete re-install XP, while I have backups, it would be my last option because I still have to lose data.

    MS KB307545 says not to use on install OEM (I have a full version of XP SP2 I could boot from it) http://support.microsoft.com/kb/307545 but did not say what you need to do.

    By pressing F8 during does not start safe mode and I can not find a mechanism beginning a system restore. I should have one from last Tuesday.

    Anyone has any ideas.

    Hello

    See this Microsoft Knowledge base article:

    + How to start the System Restore tool by using the option of safe mode with the command prompt in Windows XP +.
    http://support.Microsoft.com/kb/304449/

    If you have an original Win XP disk then you could start using this disc. The installation of Win XP supports a repair option that start you press the R key (when windows asks to press R).

    Otherwise I put t see any other option as to reinstall new OS

  • S50 satellite - B - 14 M - button and function keys switch F

    So, I posted this a few days ago on plateau "Tools & Utilities", but did not answers, then maybe I should be more patient. But, since this forum seems to be a little more active, I thought I would try it here as well. Who knows, maybe some people with a Satellite S have experienced the same thing!

    I looked for an answer on google and this forum for days, but were not able to find something useful (especially in combination with 'windows 10', I have no idea if install had no effect in the present).

    I installed Windows 10 last week, and I don't know if it's the 'problem' at the start, but since yesterday I've been aware of the fact that the 'modus special function"F - keys (i.e. the function in which you don'thave to store the function key to access the special functions under the (former) F keys) no longer works.

    I have already tried:
    -My system restarts
    -Control Panel > keyboard > function key modus (but which has been defined correctly!).
    -Tried any combination of Fn with any other possible key.

    So I don't know what the problem is. It might have something to do with the $ 10 Windows?

    Details:
    Toshiba Satellite S50 - B - 14 M
    Pre-installed with Windows 8.1, upgraded to Windows 10 Home last Tuesday

    Thanks to anyone who can help me!

    I solved it myself! Turns out I just needed another obvious solution: reinstall the utility function of key driver.

    Well done!

    Thanks for sharing the solution with us!

  • Flashing underscore at the start

    Hello

    It happened about 6 days ago but its now only ive had internet access I can post this question. Basically what has happened, on July 28, last Tuesday I was hd shut down my pc. Then I came back later in the day to return. Then it would start as usual, showing the logo of manufacturer and etc, then I see is a line of underscore/dash/hyphen / flashing line you name. So I thought something was wrong. So I turned off and turned back on the pc. came back. and ive yet to find a solution. people have suggested to insert the windows installation cd, but I still get the flashing line. I opened my PC, because I had read that it could be connected the HARD drive to the motherboard IDE cables. He went out, kicked it and put it back in. still nothing. Now, I am faced with a situation where I can't work because my files are on this PC. Can someone please suggest what to do?

    Hello Jasestyle,

    If the BIOS does not recognize the hard drive at this time, you will need to contact the manufacturer of the computer for help.  It might be that the hard drive, the wiring or even the motherboard has gone bad.

    Best regards

    Matthew_Ha

  • updates KB3045999 and kb3046269 keep installed successfully

    Windows 7 Home premium sp 1, 64-bit version. After last Tuesday (14/03/2015), updates KB3045999 and KB3046269 keeps the installation successfully, but every day I ask myself to install again. Several others on the same day impossible installation - KB2446710, KB2478662 and KB2990214. I tried several times to install those failed too.

    I see that KB2990214 is supposed to be part of a preview of a later version of Windows, and asked whether you have previously visited their site (I never have), but I continue to be offered. KB2446710 and KB2478662 look a few years old, so I am confused, why I want to come now.

    Looking at the history of update, he passed everything except that KB2990214 was the first to fail on the 15/04/2015, then there was very successful installs, then KB2990214 has not once again and I entered the situation described at the beginning.

    At any given time helped KB947821 Hotfix (update had ceased to do anything about it either - cannot remember the details now) but it does not solve the above problem.

    I made no changes to the system in recent weeks. I tried all of the utilities listed troubleshooting I found in aid of MS which did not find any problem.  I have not tried any registration (which is beyond me).

    Hi Jim,.

    Thank you for updating the State of the question.

    See the link below for this problem.
    https://support.Microsoft.com/en-us/KB/2509997

    WARNING 1:
    This section, method, or task contains steps that tells you how to change the registry. However, serious problems can occur if you modify the registry incorrectly. Therefore, make sure that you proceed with caution. For added protection, back up the registry before you edit it. Then you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click on the number below to view the article in the Microsoft Knowledge Base: 322756 (http://support.Microsoft.com/kb/322756/fr/ )

    WARNING 2:
    Running chkdsk on the drive if bad sectors are found on the hard drive, while the bad sectors can be refunded but there may be loss of data.

    Response with the State of the question, I'll be happy to help you.

  • Question about certifiction VCP

    I am Taw of the Lebanon, I spent my last Tuesday VCP exam, my score is 95. can someone help me to know how long is it to receive a vmware view, Lebanon?

    Wow, nice score.

    Congratulations and welcome aboard.  We hope to see you participate in this forum with this wealth of knowledge.

    Great job.

    If you find this or any other information useful or appropriate, please consider giving points.

  • iPhone iOS 10 5 and restart problem

    Context: a year and a half months ago my left side of the screen (iPhone 5) began to burst, an indication of battery failure. I ran to an apple certified service in the country, I've been during the holidays. They asked 100 euros and five working days, so obviously, I changed the battery in a store not certified in 1 hour (unware of the battery, they put in). With iOS 9.3.5 all was well for the whole of this period later. No problem at all.

    Problem: last Tuesday (so after one year and), I have updated to iOS 10. Once again everything was working fine, until this weekend (3 days later), where my iPhone 5 has started to reboot frequently, i.e. Saturday and Sunday should have restarted more than 20 - 30 times without reason.

    What I tried: I reset all the settings in the settings menu, I did reset function sleep and home button, I restored my iPhone IOS 10 5. Nothing. The reboot occurs again. Last thing I noticed is that the reboot occurs less frequently (100% sure) while the iPhone is in charge.

    Question: is this a software problem on iOS 10 (do not believe now to be honest), or just the coincidence of a pile of problems that have occurred with the iOS 10 update, or something else? Here, I changed the battery (76 kilos), or give the iPhone engineering to get a new one for 198 pounds?

    Any help is welcome. Thank you very much.

    I solved it. I just changed my battery. No problem since then.

Maybe you are looking for

  • Removal of music apps in dock

    Updated to OS3 on Apple Watch, and I noticed musical application in dock.  I didn't want it, but can't get rid of it.  iPhone is not docked, but shows that it is in the dock.  Trying to get rid of it, I have now 2 music apps in the dock, and I can't

  • K4D07EA #ABF: what is max ram to hp-envy 15-j192nf

    Hi all What is the maximum ram I can improve my hp envy 15, motherboard: 1967 KBC Version 93.52 Thank you.

  • Satellite A300 - constant "Webcam Driver Open Fail' error

    I have searched and looked for solutions to this problem and feel like I've tried everything. Whenever I turn on my laptop or try to start my webcam I get the error "Webcam driver open fail." Please restart camera or computer. » I used to be able to

  • disbale system: stuck on bios password

    Greetings, I have laptop HP DV4-2165dx and it is stuck on the bios password. System deactivation code: 85590280 Please, help me to reset the wood. Concerning Taylor

  • SATA on a card mother n1996

    I have a Pavilion 762n and I was wondering if there are ports for a disk sata hard.