How to find the first day of the month following two years one year from now?

Hello

I need to find the first day of the month following two years ago, based on the current date.

For example: If today is the 31/08/2015 so I need to find the date range between 31/08/2015 and on 09/01/2013. How can I write an SQL which allows to automate this calculation instead of hard-coding the values. Please do help me out with this so that I can build the SQL that can produce the desired result.

Thank you

Dhilip

find the start of the month - 2 years in advance, early - 2 years + 1 months in advance and go back 1

Select trunc (add_months(sysdate,24), 'MM'), trunc (add_months(sysdate,25), 'MM') - 1 double;

Tags: Database

Similar Questions

  • How to find the difference between two dates in time except Sunday

    Hi all

    I have a table, as shown below.
    SQL> select * from test;
    
    TR_ID                                              CREATE_TIME                                                                       CODE
    -------------------------------------------------- --------------------------------------------------------------------------- ----------
    S12341                                             05-JUN-12 12.20.52.403000 AM                                                      1003
    S12342                                             11-JUN-12 11.15.33.182000 AM                                                      1003
    S12342                                             07-JUN-12 12.00.36.573000 PM                                                      1002
    S12343                                             20-JUN-12 12.34.37.102000 AM                                                      1003
    S12343                                             15-JUN-12 11.34.27.141000 PM                                                      1002
    S12344                                             01-JUL-12 10.01.06.657000 PM                                                      1002
    S12344                                             06-JUL-12 12.01.04.188000 AM                                                      1003
    S12341                                             31-MAY-12 11.20.38.529000 PM                                                      1002
    I would like to know the difference between same tr_ids create_time, which should give out in hours except Sunday.

    For example:

    TR_ID: S12344
    1002_Create_time: July 1, 12 PM 10.01.06.657000 (i.e. Sunday)
    1003_Create_time: 12.01.04.188000 AM 6 July 12

    1002 create time is 22:00 Sunday.

    If the query must exclude only the hours of Sunday which is 10 p.m. to Monday 00 h which is 2 Hrs.

    I tried the sub query after doing a search on this forum but I am not getting the desired output.
    SELECT count(*) FROM (SELECT ROWNUM RNUM,tr_id,create_time CT_1002 FROM test c WHERE c.tr_id='S12344' and 
    ROWNUM <= (select (cast(a.create_time as date)-cast((select create_time from test b where a.tr_id=b.tr_id and code=1002) as date)) 
    from test a where a.code=1003 and a.tr_id=c.tr_id) + 1) d 
    WHERE to_char(cast((select create_time from test e where e.tr_id=d.tr_id and code=1002) as date) + RNUM - 1, 'DY') NOT IN('SUN');
    Need help to get the desired o/p

    Hello

    If I unederstand the problem correctly, that's what you want:

    WITH       got_extrema     AS
    (
         SELECT       tr_id
         ,       CAST (MIN (create_time) AS DATE)     AS start_date
         ,       CAST (MAX (create_time) AS DATE)     AS end_date
         FROM       test
         GROUP BY  tr_id
    )
    SELECT       tr_id
    ,       start_date, end_date          -- If wanted
    ,       24 * ( ( ( TRUNC (end_date,   'IW')          -- Count -1 day for every full week
                        - TRUNC (start_date, 'IW')
                 )
               / -7
                  )
                + LEAST ( end_date               -- If end_date is a Sunday
                            , TRUNC (end_date, 'IW') + 6     -- consider it 00:00:00 on Sunday
                     )
                - CASE
                          WHEN  start_date >= TRUNC (start_date, 'IW') + 6     -- If start_date is a Sunday
                   THEN  TRUNC (start_date, 'IW') + 6               -- consider it 00:00:00 Sunday
                   ELSE  start_date
                      END
                )     AS total_hours
    FROM      got_extrema
    ;
    

    I guess that you don't need to worry about fractions of a second. As you did in the code you have posted, I am to convert the TIMESTAMP to date values, because of DATE arithmetic and functions are so much better than what is available for timestamps.

    Basically, it's just to find the number of days between start_date and end_date and multiplying by 24, with these twists:
    (a) 1 day is deducted for each week between start_date and end_date
    (b) if End_date is a Sunday, none of the end_date himself hours are counted
    (c) If start_date is a Sunday, then all the start_date himself hours are counted. Why these hours should be counted? Because 1 day is already being deducted for the week which includes start_date, which contains only this Sunday.

    TRUNC (dt, 'IW') is the beginning of the ISO week containing dt; in other words, 00:00:00 the or before the dt last Monday. This is not the NLS parameters.

    Of course, I can't test without some sample data and the exact results you want from these data. You may need a little something more If start_date and end_date are both on the same Sunday.
    Whenever you have a problem, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) of all of the tables involved.
    Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
    Always tell what version of Oracle you are using.
    See the FAQ forum {message identifier: = 9360002}

  • How to find the data in two tables are the same?

    Hi people,

    Suppose we have table emp01, have 10 records and create another emp02 as table

    create the table emp02 in select * from emp01;

    now both the table has the same data.

    How to find a 'data' in the two tables are the same?

    Hello

    SELECT *
    FROM emp01
    MINUS
    SELECT *
    FROM emp02
    UNION
    SELECT *
    FROM emp02
    MINUS
    SELECT *
    FROM emp01
    

    You can also compare resultset hash to select * in emp01 and select * from emp02 by using dbms_sqlhash.

    Best regards
    Nikolai

  • How to find the difference between two dates in the presentation layer

    Hi gurus,

    Hello to everyone. Today, I came with the new requirement.


    I need to know the difference between a date and the current date in the formula column application presentation layer.by.



    Thank you and best regards,
    Prates

    Hi Navin,

    TIMESTAMPDIFF function first determines the timestamp component that corresponds to the specified interval setting. For example, SQL_TSI_DAY corresponds to the day component and SQL_TSI_MONTH corresponds to the component "month".

    If you want to display the difference between two dates in days using SQL_TSI_DAY, unlike butterflies SQL_TSI_MONTH and so on...

    hope you understand...

    Award points and to close the debate, if your question is answered.

    See you soon,.
    Aravind

  • How to find the sql queries executed in one day with the sql and runtime text

    Hi Experts,

    Please tell me the sql query to find out the queries executed on a particular day and the runtime and the sql text of the query.

    Please reply urgent.

    Thanks in advance

    Database instance 'A' may have run 100 SQL queries today.  As for the instance of database 'B' could have exploited queries SQL 1 million today.  Instance of database 'B' to 'keep' the 1 million SQL statements - in memory or on disk do you expect?  Of course not.  There the age or flush or invalidate memory SQL statements.  He can't keep them on the disk (imagine running a completely different set of 1.2million SQL statements tomorrow and 1.3 the next day).

    AWR and StatsPack can make counts the number of "n" top of the page ("n" default to 30) SQL statements which are still present in the cache of the library (not years, rinsed, invalidated) when a snapshot was taken.  They can't declare "all" SQL statements.

    To return to your needs.  WHY do you need all the SQL statements?  Or are there only certain operations specific SQL would you be interested?  Could they have been treated by allowing audit (for example, UPDATE and DELETE with EXTENDED verification instructions)?

    Hemant K Collette

  • How to find the icloud place where are my pictures from the phone?

    My iphone 6 is supposed to return the icloud p every day, how can I find my saved photos?

    You do not see the photos that are part of a return to the top.

    If you mean iCloud photo library, you can see these photos to iCloud.com > Photos

  • How to find the time between two channels of entry in the data acquisition card or pci 6036

    Hello

    I read a lot-related posts on the simultaneous measurement of two input voltage of similar channels in map data acquisition. I know that the best material is "simultaneous measurments of the Series DAQ cards" but I only pci data acquisition card 6036 and I try to understand what is the time between the reading of the two channels . This period is always constant? (must it rely on a voltage (amplitude, frequency, waveform..). I send the sine wave (s) to the two channels and read the values of V, if they read the same value, the difference should always be zero but I get-0,002 to 0.002 Volt difference (I must find a way to convert it in time). A screenshot of my VI is attached. I wonder how I can accurately measure the time delay between the channel.

    I am open to any suggestion, my final goal to read exactly two channels at the same time ((ou connaître le délai exact donc je peux correspondre les données correspondantes étant donné le temps de retard))

    Hi spinup,

    better you should post your question in the forum of LabVIEW, LabWindows/CVI is used

    Good luck.

  • HP ENVY 5644: How to find the password to be able to print from the iPad or a laptop?

    I configured the printer some time ago, but now my husband wants to print from his Mac laptop and requires the password that I do not have. How can I find out what the password please?

    Hello

    If you're connected via wifi direct, you can get the password by pressing the direct wifi on the printer control panel for 3 seconds or more, and it should print.  If you connect via wifi direct, when you open your settings on the ipad wifi, you will be connected to a network with the name of the printer that is incorporated into the name of the wifi network (and the direct button wifi will have to be reactivated at the front of the printer).

    If you are connected via your wifi router at home, your wifi password should be printer on your router somewhere.

  • How to find the hours between two times

    Hai All

    I had a problem I need to calculate work time

    For example

    Respondent outtime

    0815 1715

    So I need to calculate a time between these two times

    How can I do using function for 100 our

    Concerning

    Srikkanth.M

    Hello

    use the below the update statement.

    update dail_att set wtime =  extract(hour from (to_date(outtime,'HH24:MI')-to_date(intime,'HH24MI')) day to second);
    

    Solution of the sample...

    PRAZY@11gR1> desc dte;
     Name            Null?    Type
     ------------------- -------- --------
     INTIME           VARCHAR2(4)
     OUTTIME        VARCHAR2(4)
     HRS                NUMBER
    
    PRAZY@11gR1> select * from dte;
    
    INTIME     OUTTIME           HRS
    ---------- ---------- ----------
    0815       1715
    0900       1800
    0830       1630
    
    Elapsed: 00:00:00.00
    PRAZY@11gR1> update dte set hrs = extract(hour from(to_date(outtime,'HH24MI')-to_date(intime,'HH24MI')) day to second);
    
    3 rows updated.
    
    Elapsed: 00:00:00.01
    PRAZY@11gR1> select * from dte;
    
    INTIME     OUTTIME           HRS
    ---------- ---------- ----------
    0815       1715                9
    0900       1800                9
    0830       1630                8
    
    Elapsed: 00:00:00.00
    

    Kind regards
    Prazy

    Published by: Prazy on March 24, 2010 12:43

  • How to reset the ' do automatically for files like this frome now on "when you save a file, how to reset that?

    I accidentally select "do this automatically for files like this in the future" when opening a file. Now, whenever I open a file, it automatically asks where to save it. First of all, I would like to open it. How to reset?
    Thank you.

    If you can't do this in "tools > Options > Applications" then you can rename (or delete) the file mimeTypes.rdf in the profile folder of Firefox to reset all the actions file.

    You can use this button to go to the Firefox profile folder currently in use:

  • How to find the first Sunday and the second Saturday of each month

    Hi all

    How to find the first Sunday and the second Saturday of each month

    Thank you

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    994122 wrote:

    Hello

    I need to pass the months parameter how to do this? like Jan, Feb etc... (one of those)

    Do you have a procedure?

    Should you output only for the months you passed in the parameter?

    The easiest way is to set the parameter as date. When you go such as p_date as DATE ' 2014-10-01', then you can

    PROCEDURE two_dates)

    p_date IN DATE

    p_first_sunday DATE

    p_second_saturday DATE

    )

    IS

    BEGIN

    p_first_sunday: = NEXT_DAY (TRUNC (p_date, 'MM') - 1, TO_CHAR (DATE ' 2014-10-12', 'DAY'));

    p_second_saturday: = NEXT_DAY (TRUNC (p_date, 'MM') - 1, TO_CHAR (DATE ' 2014-10-11', 'DAY')) + 7;

    END two_dates;

    Or you describe what you need.

  • How to find the value dated the same day in the last year

    I want to know how to find the value dated the same day in the last year.

    I use now, there is the function with the year and the result is

    Year Rev There are Rev
    20113000
    201240003000
    201320004000
    201450002000

    It works but it's not that I want. I'm trying to add the column date (Ex.20140101) in my report but it'snot work.

    I want to show:

    Date Rev There are Rev
    20110112200
    20120112100200
    20130112300100
    20140112500300

    If use (< degree >, < time_dim >. < date >, 365), it works but does not correct 100%

    Please help me...

    Thank you very much

    Check this link cool - bi.com

  • OBIEE 11 g: how to find the 2nd Friday of the month

    Hello

    How to find the 2nd Friday of the month using the current date in obiee 11g.

    Thanks in advance.

    Kind regards

    MIT.

    Hey MIT,

    You can try with something like this:

    TIMESTAMPADD (SQL_TSI_DAY, TIMESTAMPADD (7 + 6-DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE))), (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE))

    It can still be improved to probably avoid transformations 1-2, but at least he does.

    You will need to check what return DAYOFWEEK in your environment for Friday (in mine Friday = 6) as if she does not return to Friday 6, you will need to adjust the formula.

    The idea is to find what day is the first day of the month, since then visit the first Friday (or just stay there if the first day is a Friday). This is done by the DAYOFWEEK 6 (first day of the month).

    And now, you just add more 7 days, so that's why there is a 7 + 6 - DAYOFWEEK (first day of the month) to make it easier to read and understand (instead of 13-...).

  • How to find the position of the VI icon currently run on the block diagram of the appellant

    Dear forum,

    I am currently trying to use a LabVIEV VI as a simple sequencer: several (very slow) actions must run one after the other. Each action is represented by a Sub - VI, some actions are executed several times. My task is to view the Subvi somehow executing.

    My first intention (just manipulate the icon of the VI running with 'Icon.Get VI as Image data' / 'Icon.Set VI of Image data' invoke nodes) has failed, because it changes all instances of the VI icon. If you use the same VI several times, all these VI icons are changed (see here: http://forums.ni.com/t5/LabVIEW/How-to-change-animate-icon-of-currently-running-VI/m-p/3120754/highl... )

    My current approach is to use an image of the block diagram (with "VI: block diagram: get resized Image ' call method) in a picture of the front panel control and working within this control. But for this I need to know the position of the icon of the VI running. I know that I can assess the limits and Position via the properties GObj, but how to find the VI running (note that a VI can be installed several times on the block diagram, so the name of the VI is not unique)? IMHO the easiest way might be if a VI might find its icon on the block of the appellant diagram itself when it is run...

    It is clear that this position is not yet the position on the photo, but this conversion is a small piece of work...

    Kind regards

    cpschnuffel


  • How to find the value max and min for each column in a table 2d?

    How to find the value max and min for each column in a table 2d?

    For example, in the table max/min for the first three columns would be 45/23, 14/10, 80/67.

    Thank you

    Chuck,

    With color on your bars, you should have enough experience to understand this.

    You're a loop in the table already.  Now you just need a function like table Max and min. loop.  And you may need to transpose the table 2D.

Maybe you are looking for

  • Strange noise coming from the fan on Satellite P100

    My Satellite P100 just makes a noise like a seriously heavy drill. Nothing else happened significantly so I turned off immediately and left for an hour or so overheating had the broken fan.Now back on and everything seems fine, but I'm worried. Is th

  • This Virus warns a fake?

    I was trying to go to a website and instead of receiving a box that had a Safari logo warning me that I visited just a site that has downloaded a virus on my MAC and asking me to click on the button to start a repair. It froze my computer. I did a fo

  • Order the various calendars at once, is possible?

    I have 5 different projects, calendars, but I wasn't able to order all five at once... only one by one... Is it possible to make a single order? Thank you!

  • What is the current version of csrss.exe for windows XP

    I'm under ' Microsoft Windows XP Professional Version 2002 Service Pack 3. The version of csrss.exe I have on my machine is: 5.1.2600.5512 This is the latest version? If this isn't the case, should I update? If update is recommended, where can I down

  • HP 15-1039wm: the Bios PW reset

    I stupidly forgot the pw of my computer's bios, can anyone help? I typed in what I thought it was 3 times, and I got these numbers: 51743269 Thanks for everything and all the HELP :-)