How to caluclate tat between two dates of a timestamp field
Hellocould help to caluclate days between two dates and unique timestamp filed with this
query
Select * from m_activity_transaction where actn_opp_id in)
Select actn_opp_id in the m_activity_transaction where ACTN_ACTV_ID = 218
Actn_opp_id group
view count (*) > 1) and ACTN_ACTV_ID = 218
order of actn_performed_on
IAM get output is
ACTN_ID ACTN_OPP_ID ACTN_PERFORMED_ON
319415 95831 JANUARY 27, 12 AM 11.06.20.000000
315249 95831 8 FEBRUARY 12 05.32.54.000000 PM
301927 103509 20 DECEMBER 11 04.01.43.000000 PM
301458 103509 19 DECEMBER 11 04.51.03.000000 PM
294841 115840 10 JANUARY 12 03.20.12.000000 PM
312062 115840 11 JANUARY 12 05.17.06.000000 PM
Normand to caluclate number days between two dates like January 27, 12 AM 11.06.20.000000 and I 05.32.54.000000 8 February 12 PM where actn_id is unique AND ACTN_OPP_ID IS NOT UNIQUE.
Thanks in advance,
VVR.
In this way.
with data as
(
select 315249 a, 95831 b, to_date('27-JAN-12 11.06.20 AM', 'DD-MON-RR HH.MI.SS AM') dt from dual union all
select 319415, 95831, to_date('08-FEB-12 05.32.54 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
select 301927, 103509 , to_date('20-DEC-11 04.51.03 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
select 301458 , 103509 , to_date('19-DEC-11 04.01.43 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
select 363810 , 144656 , to_date('27-JUN-12 12.43.28 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
select 363500 , 144656 , to_date('26-JUN-12 11.41.50 AM', 'DD-MON-RR HH.MI.SS AM') from dual union all
select 363354 , 144656 , to_date('25-JUN-13 12.41.13 PM', 'DD-MON-RR HH.MI.SS AM') from dual
)
select a, b, diff_in_days
from (
select a, b, trunc(dt - lag(dt) over (partition by b order by dt, a)) diff_in_days
from data
) tab
where tab.diff_in_days is not null;
A B DIFF_IN_DAYS
---------------------- ---------------------- ----------------------
319415 95831 12
301927 103509 1
363810 144656 1
363354 144656 362
Tags: Database
Similar Questions
-
How to find days between two dates in days
Hi, I want to get the days between two dates, expressed in days, how can I do this? For example, I date i.e. 1 October 10, 2013 (Thursday) and 2 as October 13, 2013 (Sunday). How can I get a production of:
Thursday, Friday, Saturday and Sunday, which are the days between Oct. 10-13, 2013. I hope you understand my point. Thank you
You can try something like this
CURSOR LOAD_PROF is
SELECT load_prof1, v_time_profile_day
OF load_profile_test
WHERE profile_day IN (select TO_CHAR(:day1+level-1,'Day')
of the double
connect by level<>
);
Kind regards
S Pax
-
How to view - (hyphen) between two dates
My requirement is if I select the 'count' and 'to date' in the dashboard to the release of the report to display as "date-to date" could any body please help grow me in this...Hello
If you want to use the strategy of Mahesh, you cannot use the BETWEEN operator. You will need for different layout columns, with a DATE data type and two presentation variables. Then, in your report, instead of saying: YOUR_DATE IS INVITED, you will need something like YOUR_DATE between @PRES_START_DATE AND @PRES_END_DATE.
If you absolutely must use the BETWEEN condition, then you will need to define two new logical columns in your file of RPD. These two logical columns will be MIN and MAX of the column in question. When you pull these in your report, they will return the MIN and MAX date values that lie in BETWEEN your condition. You can then use the @
- @ syntax to display two dates with a hyphen. Hope this helps and if you need more information, do not hesitate to ask.
Best regards
-Joe
-
How to alternate Mondays between two dates?
Hello
I try to get the dates for other occurrences of a given day (say Monday) in a given range of dates. How is it possible in a SQL query? Thanking you in advance.
Hello
Here's one way:
WITH params AS
(
SELECT NEXT_DAY (TO_DATE (February 7, 2014 ', 'DD-Mon-YYYY') - 1).
, 'MONDAY '.
) AS start_date
, TO_DATE (31 March 2014 ', 'DD-Mon-YYYY') AS end_date
OF the double
)
Start_date SELECT + ((LEVEL-1) * 14) AS a_date
OF params
CONNECT BY LEVEL<= ceil="" ((end_date="" +="" 1="" -="" start_date)="">=>
;
Of course, you can easily change start_date and end_date and the day of the week target also, to all you want.
This assumes that NLS_DATE_LANGUAGE = ENGLISH. If you can not sure about NLS_DATE_LANGUAGE, then the same basic idea works, but the function calls are a bit messier.
I hope that answers your question.
Otherwise, put one or two series of the summer (start_date, end_date, day_o_week) and the desired results of each set. Point where the above query was to produce erroneous results, and explain how to get good results in these places.
-
How can I determine if the current date is between two dates?
I'm trying to post a link when grave the current date between two dates. I have setup the startdate and the enddate. When he falls between the startdate one date enddate, the link will be apear. The startdate and enddate have already been formatted previously, as mm/dd/yyyyy. I tried to use the following script, nothing will do. What I am doing wrong?
< cfif startDate GTE #dateformat (now (), "MM/DD/YYYY") # AND enddate LTE #dateformat (now (), ' MM/DD/YYYY') # >
Don't know what you're talking about. I used the #dateformat(date_entered, 'mm/dd/yyyy') # for years without problem. I googled the datediff function before posting here and what I've found is datediff determines the whole number of units by which date1 is less than date2. I don't know how this can help me.
-
How to return all dates between two dates?
Hi all
I need get all dates between two dates, Oracle SQL and PL/SQL.
for example
How can I get these values? Any help will be useful.01/10/2011 - date 1 10/11/2011 - date 2 # Return Values 01/10/2011 10/02/2011 03/10/2011 . . . 09/11/2011 10/11/2011
Thank youMaybe
select :start_date + level - 1 the_date from dual connect by level <= :end_date - :start_date + 1
Concerning
Etbin
-
How do the time difference between two dates?
Hi all
I use this query to get the time difference between two dates.
Select to_timestamp ('2012-10-03 12:00 ',' YYYY-MM-DD hh)-to_timestamp ('2012-10-03 11:00 ',' YYYY-MM-DD hh) as double diff;
but do not get the correct result.
Thank youLeft KEY... Left Padding of tanks.
-
How to get the date between two dates, except Saturday and Sunday
Dear all,
The query above returns the following outputselect to_date('25-04-2012', 'DD-MM-YYYY') + rownum -1 dt from dual connect by level <= to_date('05-05-2012', 'DD-MM-YYYY') - to_date('25-04-2012', 'DD-MM-YYYY') + 1;
Here, I need to exclude Dates that lights up "Saturday" and "Sunday" and also the joint birthday partyDT DT 04/25/2012 04/26/2012 04/27/2012 04/28/2012 04/29/2012 04/30/2012 05/01/2012 05/02/2012 05/03/2012 05/04/2012 05/05/2012
Here it is May 1, 2012 "and I need the output as follows,
I need the current request to calculate between two dates.04/25/2012 04/26/2012 04/27/2012 04/30/2012 05/02/2012 05/03/2012 05/04/2012
Can anyone suggest me?
Thank you
Regsrds,
gurujothiselect dt from( select to_date('25-04-2012', 'DD-MM-YYYY') + rownum -1 dt from dual connect by level <= to_date('05-05-2012', 'DD-MM-YYYY') - to_date('25-04-2012', 'DD-MM-YYYY') + 1 ) where to_char(dt,'fmday') not in ('sunday','saturday')
To exclude, common holiday, you must have a host table. Then use an OUTER JOIN NOT IN or NOT EXISTS
-
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 -
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
-
Dynamic calculation of the number of days between two dates in a table
Hello
I'm working on request where I dynamically calculate the number of days between two dates in a table.
The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.
APEX version: 5.0
Hi BO123,
BO123 wrote:
Hello
I'm working on request where I dynamically calculate the number of days between two dates in a table.
The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.
APEX version: 5.0
one of the way to do this by calling ajax on change of end_date.
See the sample code given below to fetch the resulting duration and making the field read only after calculation
Step 1: Change your page
under CSS-> Inline, put the code below
.row_item_disabled { cursor: default; opacity: 0.5; filter: alpha(opacity=50); pointer-events: none; }
Step 2: Create on demand Ajax process I say CALC_DURATION
Please check Procces Ajax, see line 6.7 How to assign a value to the variable sent by ajax call
Declare p_start_date date; p_end_date date; p_duration number; Begin p_start_date := to_date(apex_application.g_x01); p_end_date := to_date(apex_application.g_x02); --do your calculation and assign the output to the variable p_duration select p_end_date - p_start_date into p_duration from dual; -- return calculated duration sys.htp.p(p_duration); End;
Step 3: Create the javascript function
Change your page-> the function and the declaration of the Global Variable-> put the javascript function
You must extract the rowid in the first place, for which you want to set the time, see line 2
assuming f06, f07 and f08 is the id of the start date, and end date columns respectively, and duration
See no line no 8 how set the value returned by the process of ajax at the duration column
Replace your column to the respective column identifiers in the code below
function f_calulate_duration(pThis) { var row_id = pThis.id.substr(4); var start_date = $('#f06_'+row_id).val(); apex.server.process ( "CALC_DURATION", { x01: start_date,x02: $(pThis).val() }, { success: function( pData ) { // set duration to duration column $('#f08_'+row_id).val(pData); // disable duration column $("#f08_" + row_id).attr("readonly", true).addClass('row_item_disabled'); } }); }
Step 4: choose the end date call the javascript function
Go to report attributes-> edit your Date column end-> column-> Attrbiutes element attributes-> put the code below
onchange="javascript:f_calulate_duration(this);"
hope this helps you,
Kind regards
Jitendra
-
Number of Saturdays between two dates
Hello
How can I get number of Saturdays between two dates, including the two dates?
for example number of Saturdays between 09/05/2014 and 10/05/2014 is five
Help, please
I use oracle 10g
SQL> with t 2 as 3 ( 4 select to_date('05/09/2014 ', 'dd/mm/yyyy') from_dt 5 , to_date('05/10/2014 ', 'dd/mm/yyyy') to_dt 6 from dual 7 ) 8 select to_char(from_dt + (level-1), 'fmDay') day_ 9 , count(*) cnt 10 from t 11 connect 12 by level <= to_dt - from_dt + 1 13 group 14 by to_char(from_dt + (level-1), 'fmDay'); DAY_ CNT --------- ---------- Saturday 5 Thursday 4 Tuesday 4 Friday 5 Wednesday 4 Monday 4 Sunday 5 7 rows selected. SQL>
-
Hello
I have two dates. start date and end date.
I want to extract months between two dates
months should be as
JAN
FEB
MAR
for example.
Start - 1-jan-2014
date of end - 31 - dec - 2014
How can I do this?
Thanks and greetings
CORINE
You should always use the function MONTHS_BETWEEN...
for example
SQL > ed
A written file afiedt.buf1 with t as (select date '' 2014-01-01 as start_date date ' 2014-12-31' as double end_date)
2 --
3 end of test data
4 --
5. Select to_char (add_months (start_date, rownum-1), 'My') by month
6 t
7 * connect by rownum<=>=>
SQL > /.LUN
---
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Ms
Oct
Nov
Dec12 selected lines.
And if you want that they display, separated by commas...
SQL > ed
A written file afiedt.buf1 with t as (select date '' 2014-01-01 as start_date date ' 2014-12-31' as double end_date)
2 --
3 end of test data
4 --
5 Select listagg (to_char (add_months (start_date, rownum-1), 'My'), ',') group by month (order by rownum)
6 t
7 * connect by rownum<=>=>
SQL > /.MONTH
-----------------------------------------------------------------------------------------------------------------
Jan, Feb, Mar, Apr, may, June, July, August, Sept, Oct, Nov, Dec -
Number of weeks between two dates that are in the same or different year
Hello
How to calculate the number of weeks between two dates?
for example. "" "17-mar-2013' and June 27, 2013" or June 15, 2013 "and" 25-mar-2014
Thanks in advance.
lukx
Hello
Looks like your date range is incorrect.
Please try the below.
SQL >-front right
SQL > select D2 - D1 "days."
2 round ((D2-D1)/7.0) "weeks."
3 round (Months_between (d1, d2), 0) 'months '.
(select 4
5 TO_DATE ('20121201', 'YYYYMMDD') D1, D2 TO_DATE ('20130116', 'YYYYMMDD')
6 from two
(7) date_range;
Elapsed days weeks months
------------ --------- ---------
46 7 1
-
Need assistance with obtaining data of users modified between two dates in IOM
Hi all
I have a 11g IOM environment where I need to write a scheduled task that needs to go out the data of users that have been modified between two dates. After the search in the forums, I've had an idea and wrote the following code for the same thing. But it doesn't seem to work. Can someone help me here please?
> //initialize upper and lower attributes to two values of oracle.sql.DATE
> Criteria1 SearchCriteria is nothing, Criteria2 = null, criteria;
> criteria1 = new SearchCriteria ("update the", lower, SearchCriteria.Operator.GREATER_EQUAL);
> Criteria2 = new SearchCriteria ("update the", plus top, SearchCriteria.Operator.LESS_EQUAL);
> criteria = new SearchCriteria (Criteria1, criteria2, SearchCriteria.Operator.AND);
> //initialize the necessary parameters, obtain a User Manager object and follow these steps
> users = umgr.search (criteria, attrNames, settings);
But this doesn't seem to work. Can someone shed light on this you? The attribute "updated on" is not available for this task? If I use a unique 'User login' attribute search criteria, this thing works and gets the user data but this does not work when I use the attribute "updated on" so made me think maybe that this attribute is not available for use via the API or something. Or maybe it's with the help of the oracle.sql.DATE is a problem here. Not sure if. So kindly help me with this.
Thanks in advance,
$idI suggest that create you a real attribute in your scheduled task called something like 'Last Run Timestamp'. The reason why I say this is that you can modify your search on this basis rather than manipulate the date of beginning and end of the last run. To retrieve the value, like any other attribute use this:
>
String lastRunTimestamp = hashMap.get ("last Run Timestamp") m:System.NET.SocketAddress.ToString ();
>
Format your time you are entered like this: "YYYY-MM-DD hh: mm: zzz ' in order to retrieve and format the value like this:
>
SimpleDateFormat time = new SimpleDateFormat ("yyyy-MM-DD hh: mm: zzz");
recover start date, so it can be updated on the ground on the scheduled task
Start date = new Date();Convert timestamp last executed so far
Date stamp = new Date();
timestamp = time.parse (lastRunTimestamp);
>
You have now your last time stamp execution that you can set your time dérirez based on.And finally, to return the last value of stamp on both scheduled run time, you started this task
>
SchedulerService task = Platform.getService (SchedulerService.class);
Task = task.lookupScheduledTask taskEntry (getName ());
JobParameter = taskEntry.getParameters () .get ("last Run Timestamp") jobparam;
JobDetails job = task.getJobDetail (getName ());
HashMapattributes = job.getAttributes ();
String timestamp = (time.format (start));
jobparam.setValue (timestamp);
Attributes.put ("last Run Timestamp", jobparam);
job.setAttributes (attributes);
task.updateJob (job);
>I hope it's useful. This is how I do all my scheduled tasks that need a timestamp.
-Kevin
Maybe you are looking for
-
All of a sudden I can't create Apple Lossless AIFF or WAV files versions. Yes, I know that he moved into the submenu file. That's happened? Dave
-
9.3.2 GPS and Bluetooth degraded service
I started having problems with my GPS and Bluetooth. GPS is not able to follow in my mapping applications, including Google Maps and Waze cards. At the same time, my Bluetooth headset quality is terrible. I tried the headset on other phones and it wo
-
Is there a trial period I can test the Pages ability to open Word documents on my iMac?
Is there a trial after the purchase period, during which I can test the Pages ability to open Word documents on my iMac?
-
achievement of shanghai second dynasty to run on 2007
I have a new dell and you want to run my game preferred by activision, Shanghai second dynasty. But it won't work. Any ideas?
-
Why Windows Movie Maker publish not my film with a weird color distortion?
I had this problem for a while. I have updated my graphics card and uncontrolled filters ending with that, though, is to always have this problem. Here is a picture of what it looks like: http://i256.Photobucket.com/albums/hh191/sunyboy54/capture.jpg