Select the mountains between two dates
Hi allHow can I select all months between two dates. For example, if two dates are say 2008-05-25 and 2009-07-15, then I need following output
May-2008
June-2008
July-2008
August-2008
September-2008
October-2008
November-2008
December-2008
January-2009
February-2009
March-2009
April-2008
May-2009
-June 2009
July-2009
Thank you
Sujnan
Try this one
SQL> SELECT TO_CHAR(add_months(TRUNC(to_date('25/05/2008','DD/MM/YYYY'),'MM') ,(level-1)),'fmMonth-YYYY')
2 FROM dual
3 CONNECT BY level <= months_between(to_date('15/07/2009','DD/MM/YYYY'),to_date('25/05/2008','DD/MM/YYYY')) + 2;
TO_CHAR(ADD_MO
--------------
May-2008
June-2008
July-2008
August-2008
September-2008
October-2008
November-2008
December-2008
January-2009
February-2009
March-2009
TO_CHAR(ADD_MO
--------------
April-2009
May-2009
June-2009
July-2009
15 rows selected.
SQL>
Tags: Database
Similar Questions
-
Calculate the hours between two dates
Hello
I have a requirement to count the hours with 2 given timestamps, something like:
However, I wish it would be that simple. I just need to count the hours between two timestamps for the hours of work for example, 08:00 - 17:00, MONDAY to Friday (excluding weekends).SQL> select ((to_date('22-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss') - to_date('20-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss'))*24) B from dual ; B ---------- 48
So lets say I have to count the hours between two dates above the result should be 18 hours not 48 (4 hours on 20/oct, 9 hours on 21/oct to 5 hours 22/oct).
How can I achieve this? Any idea will be useful.
Thank youMy query generates a list of all the hours between the start and end time, filters on the hours that are outside of the hours of work and then account for the remaining lines. Change that to partial hours must just be a case of replace the two occurrences of 1/24 with 24/01/60, then - as say you - Division COUNT (*) by 60.
There may be performance issues using techniques of generation of line like this, if you put this in a query involving the joining of several lines of other tables (for example where the dates of beginning and end are derived from several employees?) or in several days. If you don't find it then count the number of whole days (taking weekends into account) between dates and work on the partial days after that it could be better. This would probably involve a lot of statements of case (which I don't have time to test it now).
Ben
-
Display the months between two dates
Hello:
I need all the months between two dates. I entered two dates as January 15, 2001 and 2011-mar-03. I want the result as below.
JANUARY 15, 2011 - JANUARY 31, 2011
February 1, 2011 - February 28, 2011
MARCH 1, 2011 - MARCH 3, 2011
I held this result of sql query in oracle. Could you please suggest me?
Thanks in advance.
AbhishekSELECT GREATEST(st, ADD_MONTHS(TRUNC(st, 'MONTH'), (LEVEL - 1))) dt, LEAST(ed, LAST_DAY(ADD_MONTHS(TRUNC(st, 'MONTH'), (LEVEL - 1)))) ld FROM (SELECT DATE '2011-01-15' AS st, DATE '2011-03-03' AS ed FROM DUAL) CONNECT BY LEVEL <= MONTHS_BETWEEN(TRUNC(ed, 'MONTH'), TRUNC(st, 'MONTH')) + 1 ORDER BY 1; DT LD ------------------------ ------------------------ 15.01.2011 00:00:00 31.01.2011 00:00:00 01.02.2011 00:00:00 28.02.2011 00:00:00 01.03.2011 00:00:00 03.03.2011 00:00:00
HTH, Urs
-
Find the difference between two date and time
Hi friends,
I wanted to find the difference between two date and time, but my qury is slightest error "invalid number."
select sql_step_num,proc_name,run_seqno,start_date,end_date,(to_char(start_date,'HH24-MI-SS') - to_char(end_date,'HH24-MI-SS') ) as ed from eval.EVAL_RUNTIME_DETAILS where trunc(start_date) = trunc(sysdate) order by sql_step_num;
You try to get the feel between two char strings.
And more difference between two dates gives a NUMBER of days.
Try this:select sql_step_num,proc_name,run_seqno,start_date,end_date,numtodsinterval(end_date-start_date,'DAY') as ed from eval.EVAL_RUNTIME_DETAILS where trunc(start_date) = trunc(sysdate) order by sql_step_num;
-
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,
PratesHi 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 -
Dynamic action - Get the difference between two dates + times
I have problems a little dynamic to work action. I'm trying to get the time between two dates with the time difference.
Here is what I got (this is apex 4.0):
Two date pickers + two numbers fields (date/start/end times)
I created a dynamic action on the page who fires on the point lose focus (above points).
The real action for the DA is the body of the PL/SQL function:
When I change the values on the page, I get the following error:declare end_date DATE; start_date DATE; Begin start_date := to_char(:P1_START_DATE || ' ' || :P1_START_TIME, 'DD-MON-YYYY HH:MIAM'); end_date := to_char(:P1_END_DATE || ' ' || :P1_END_TIME, 'DD-MON-YYYY HH:MIAM'); :P1_HOURS := end_date-start_date; End;
AJAX call back Server error ORA-06502: PL/SQL: digital or value error: character number conversion error to set the value.
I'm guessing that there is a problem with the date formatting, but I can't make it work. Thanks in advance!Hi djston,
because you chose the dynamic action of 'Set value' with the "Body of the PL/SQL function" type you need to return the value. Try the following code
declare end_date DATE; start_date DATE; Begin start_date := to_date(:P1_START_DATE || ' ' || :P1_START_TIME, 'DD-MM-YYYY HH:MIAM'); end_date := to_date(:P1_END_DATE || ' ' || :P1_END_TIME, 'DD-MM-YYYY HH:MIAM'); RETURN (end_date-start_date)*24; End;
and P1_REQUESTED_HOURS like 'item affected. "
Concerning
Patrick
-----------
My Blog: http://www.inside-oracle-apex.com
APEX 4.0 Plug-Ins: http://apex.oracle.com/plugins
Twitter: http://www.twitter.com/patrickwolfPublished by: Patrick Wolf on January 17, 2011 10:54
-
counting the days between two dates
I have 3 columns in my table
date of purchase date sold days
computer 24 April 09-11 May 09
How can I write that a sql statement will help me to create a new column days and days between date bought and sold
Thank you872959 wrote:
I have 3 columns in my tabledate of purchase date sold days
computer 24 April 09-11 May 09How can I write that a sql statement will help me to create a new column days and days between date bought and sold
Thank you
just subtract two dates & the difference will be in units of days
SQL > select to_date('11-MAY-09','DD-MON-YY') - double TO_DATE('24-APR-09','DD-MON-YY');
TO_DATE('11-MAY-09','DD-MON-YY')-TO_DATE('24-APR-09','DD-MON-YY')
-----------------------------------------------------------------
17Published by: sb92075 on July 19, 2011 10:26
-
Formula to determine if a specific day of the week between two dates?
I am creating a spreadsheet to track my time PD & holiday. I usually work weekends, and my vacation allowance includes a specific maximum number of Sundays a year. Is there a way to calculate how much Sunday fall between a date range (or any day of the week, by the way)?
(i.e. If my vacation starts February 1, 2016 and ends March 2, 2016, Sunday how are included?)
I know that I can calculate how many weeks have passed, using = Quotient (DateDiff (Start_Date, End_Date), 7), but it is possible to include two Sundays in a period of 7 days.
Hi Eric,.
Here is one approach.
C2 = A2 + (7−WEEKDAY(A2,2))
This concludes the first Sunday following the start date.
D2 = STRIPDURATION ((B2−C2) ÷7)
I formatted this column without decimal places to see full weeks of the first numbers Sunday.
Quinn
-
Excerpt from the hours between two dates
Hello
This is the value stored in the table of my database.
I want to extract betwwen hours two dates. How can I extract it.
I try to run like this
Select to_timestamp('27-JAN-14 05.30.00.000000 PM')-to_timestamp('26-JAN-13 08.20.00.000000 PM') double, but it gives the answer as the format 21:10:00.000000000 + 000000365
I want simple hours, minutes, and seconds
What is the format of this value as "dd-MON-yy."
27 JANUARY 14 01.30.00.000000 PM
26 JANUARY 14 06.22.32.170033 PM
Use the Extract function. Like this.
() AS T1 (C1)
Select to_timestamp('27-JAN-14 05.30.00.000000 PM')-to_timestamp('26-JAN-13 08.20.00.000000 PM') of double)
SELECT EXTRACT (DAY OF C1) | ' DAYS '.
EXTRACT (HOUR OF C1) | ' HOURS '.
EXTRACT (MINUTE OF C1) | ' MINUTES '.
EXTRACT (SECOND C1) | ' SECONDS
FROM T1;
OUTPUT:
365 DAYS 21 HOURS 10 MINUTES 0 SECONDS
If not try it.
SELECT EXTRACT (DAY OF to_timestamp('27-JAN-14 05.30.00.000000 PM')-to_timestamp('26-JAN-13 08.20.00.000000 PM')) | ' DAYS '.
EXTRACT (HOUR FROM to_timestamp('27-JAN-14 05.30.00.000000 PM')-to_timestamp('26-JAN-13 08.20.00.000000 PM')) | ' HOURS '.
EXTRACT (to_timestamp('27-JAN-14 05.30.00.000000 PM')-to_timestamp('26-JAN-13 08.20.00.000000 PM') MINUTE) | ' MINUTES '.
EXCERPT ((SECOND from to_timestamp('27-JAN-14 05.30.00.000000 PM')-to_timestamp('26-JAN-13 08.20.00.000000 PM')) |) ' SECONDS
DOUBLE;
Post edited by: Parth272025
-
How to find the difference between two dates in time except Sunday
Hi all
I have a table, as shown below.
I would like to know the difference between same tr_ids create_time, which should give out in hours except Sunday.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
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.
Need help to get the desired o/pSELECT 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');
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} -
By selecting the difference between two images
Hello
I have two photos exactly the same thing that I took using a tripod, studio lighting and general conditions. However, in the second photo, I inserted a subject - in this case a sculpture complex. Photoshop can merge these two images together AND choose so the difference between the two images - in this case the sculpture complex?
Basically, I need to select the sculpture and do not want to spend time manually selecting due to its complexity. I need to separate the background and the sculpture for editing on their own layers.
Thank you
Stephen-CS3
You posted this in the two forums, its been answered in the mac forum.
-
How to tell the difference between two dates
Hello:
I have a question on how to get the difference in quantities for two dates in the replies and dashboard.
This is the scenario. I have two guests date and three columns. The first column must be the sum of the amounts for the first quick date. The second column should be the sum of the amounts for the second fast date. And the third column is the difference between the first two columns.
Basically, I'm trying to do something similar to a function of sum of two lines but trying to get the difference between the two rows. Any help to solve this problem would be appreciated.Use the COLUMN FILTERS level...
the first column with the first variable of date quick presentation of the filter
Similarly, the second column in the second variable of quick overview of date filter
Kind regards
Rambeau -
How to calculate the hours between two dates by the numbers
If I update 09:00 start time 17:00 end time of shift in C3 and B3, how to use a D3 formula to calculate the number of hours between the two? Then I can just copy down the lines for nth years...
It is a spreadsheet of the part-time staff payroll.
I'm sure that a lot of people out there have done that.
Help, please.
Thank you.
Eddie
What program of worksheet that you are using? Since you have a newer iMac running El Capitan, I can safely assume that you use NOT AppleWorks, which is a Power PC application that can run on any OS newer than the snow leopard, OS X 10.6.8.
If you use numbers, try to repost your question in numbers for Mac forum. If you use Microsoft Excel, try posting in the Microsoft forums. LibreOffice also has community support.
-
Calculation of the sum between two dates
Hello
I had a requirement I need to calculate the total call volume between start and end date in the repository. Can someone help me with logic?
Thank you
Try this
BOX WHEN DATE BETWEEN START_DATE AND END_DATE THEN
END OF COUNT (CALL_VOLUME), 0 OTHERWISE.
Thank you
-
photo selection between two dates
In Photos
It is possible to select photos between two dates?
In Photos,.
is it possible to select the photos between two dates?
Thank you, thank you
Yes. With a smart album like this:
Maybe you are looking for
-
purchase could not be completed
Please help me I can't buy items
-
Can I use a wildcard character in a function?
I want to search only for values that are not empty. Can I use wildcards for this? Here is an example. The data table above changes over time and fill empty values. I wish the bottom table is always current, with just the value more far to the bottom
-
Hello!I have a Satellite A215-s4747 and updating my bios driver, the computer crashed. Now I can turn on my laptop, but there is nothing. How I can fix this or do I have to reprogram my bios chip, if it can be reprogrammed? Thank you
-
How to reset the counter at each iteration, and how to introduce a delay
Hello world First of all I apologize for the basic level of my questions, I'm new with Labview... I'm counties of reading out of a USB-6008 labview chip using the DAQ assistant and I write the output to a file. The problem is that instead of giving m
-
I am running Windows 7 Professional with Service Pack 1 Until recently, when I've quand j' ai ejecte ejected a SD card, using the function of safe ejection is by left-clicking on it, its information and the map disappears from Windows Explorer and ev