Select entries between two dates by converting Unix timestamp in Oracle Dat
Hi,
I need to select the entries between two dates from an Oracle db. The Oracle db has a column with Unix timestamps. I use the following querry, but it doesnt seem to be working as desired.
select count(*) from reporter_status where to_char(FIRSTOCCURRENCE, 'mm-dd-yy') between ('08-07-06') and ('08-08-06');
FIRSTOCCURRENCE has the Unix timestamps.
Could anyone help me out with this. Thank you for your help.
Assuming that it is actually a UNIX timestamp, then it is the number of seconds since Jan 1, 1970, so you need something like:
SELECT COUNT(*)
FROM reporter_status
WHERE TO_DATE('01-Jan-1970', 'dd-mon-yyyy') + (firstoccurrence/24/60/60)
BETWEEN TO_DATE('08-07-2006', 'mm-dd-yyyy') AND
TO_DATE('08-08-2006, 'mm-dd-yyyy');Did Y2K not teach us anything? Use 4 digit years.
John
Similar Messages
-
Select Query Between two dates...
Hi Guru's,
I need a Select Query between two dates, also if the record not found for any in between date then it should return NULL or 0 ...
for Example
1. I am having two records in DB for date 2-10-2008 & 4-10-2008
2. Now suppose I have given Query for date between 1-10-2008 to 5-10-2008
Then it should return me 5 records with valid values for 2 & 4 and NULL for other 1,3,5
Thanks.Try like this:
with
t as
select date '2008-10-02' as dt, 'Record #1 (in DB)' as str from dual union all
select date '2008-10-04' as dt, 'Record #2 (in DB)' as str from dual
select v.dt, t.str
from (
select date '2008-10-01' + level - 1 as dt
from dual
connect by level <= (date '2008-10-05' - date '2008-10-01') + 1
) v
left join t
on v.dt = t.dt
order by 1 -
I can't really seem to get this straightened out.
SELECT distinct DATE, gross_total_return
FROM WPI_ICL
CASE Between '01-01-1980' AND '09-30-2008'
AND description = 'Broad Market Index United States Property (US Dollar)'
ELSE
description = 'S&P United States Property Residential (US Dollar)'
END
So, if records are between two dates, select a certain description, ELSE select a different description. I've tried IF...Then, and I've tried Case too. So far, nothing has worked out.
Can someone please give me a point in the right direction?
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.Here's a working example:
DECLARE @wpi_icl TABLE (date DATE, gross_total_return FLOAT, description1 VARCHAR(100), description2 VARCHAR(100))
INSERT INTO @wpi_icl (date, gross_total_return, description1, description2)
VALUES
('2008-09-29', 100.0, 'Broad Market Index United States Property (US Dollar)', 'S&P United States Property Residential (US Dollar)'),
('2008-10-01', 200.0, 'Broad Market Index United States Property (US Dollar)', 'S&P United States Property Residential (US Dollar)')
SELECT date, gross_total_return,
CASE WHEN date BETWEEN '1900-01-01' AND '2008-09-30' THEN description1
ELSE description2
END AS description
FROM @wpi_icl
From the code you posted, it seems you're unsure of the syntax of CASEs.
There are two ways to use a case. The first is the example above. You enclose the conditions between CASE and END.
Each condition has its own WHEN with a clause that evaluates to true or false. This clause can be made up of as many conditions as you like. After the clause comes a THEN. This is essentially what you want to happen if the clause returns true. WHEN/THEN is
synonymous with IF/THEN in this instance.
Including an ELSE is optional, but, be aware if you do not, and none of your WHEN clauses evaluate to true, you will have a NULL returned.
CASE
WHEN theseDriods = theDriodsWereLookingFor THEN callVader
WHEN theseDriods <> theDriodsWereLookingFor THEN moveAlong
ELSE goHomeAndRethinkLife
END
The other (less common) option operates like a SWITCH in some other languages. Its still surrounded by CASE and END but this time, the when just contains a value to be compared to the value at the start of the case:
CASE 16
WHEN 15 THEN 'too low'
WHEN 16 THEN 'just right'
WHEN 17 THEN 'too high'
END
Hope this helps. -
Select Between two date ranges from xml file
Hi ,
I have a column date_ with datatype VARCHAR2(150) it stores
data as
05/19/2010 11:23 AM
05/20/2010 12:23 PM
05/22/2010 11:23 AM
05/25/2010 11:23 AM
i have to select all the rows between 05/19/2010 and 05/22/2010 how to do that this column is in xml fileI have a table wit two fields
Field1 is integer and field2 is xmltype
in the xmltype i store an xml file
<ParentNode>
<Node>
<Cat>1</Cat>
<Date>05/19/2010 11:23 AM </Date>
</Node>
<Node>
<Cat>2</Cat>
<Date>05/20/2010 12:23 PM </Date>
</Node>
<Node>
<Cat>3</Cat>
<Date>05/22/2010 11:23 AM </Date>
</Node>
</Parentnode>
I am using teh below query to retrive teh result
SELECT T.Feild1, XML.* FROM Tablename T,
XMLTable( 'Parentnod/Node' PASSING T.Feild2 COLUMNS Cat NUMBER PATH 'Cat' ,
DATE_ VARCHAR2(100) PATH 'Date'
)XML where cat >1;
now i have to do teh same to select the rows between two date range 05/19/2010 and 05/21/2010
hope i am able to make teh question simple -
Find the difference between two dates for the specific month and year
Hi,
I have two dates, start date is 30/12/2012 and end date is 04/01/2013. Using datediff I found the difference of days between two dates. But I find the no of days in January 2013. ie output is 4 instead of 6. I input month and year to find the no of days
for that date. In this case I input Jan 2013. How can I sql this ?I don't understand how most of the answers provided here not analytically solving the problem with many cases possible.
First let me understand you:
You have 2 dates range and you want to calculate day range for specific month and year between the original date range.
declare @for_month int = 1 --January
declare @for_year int = 2013
declare @StartDate date = '2012-12-20'
declare @EndDate date = '2013-01-04'
SELECT
CASE
WHEN (DATEPART(MONTH, @StartDate) = @for_month and DATEPART(MONTH, @EndDate) = @for_month) and ((DATEPART(YEAR, @StartDate) = @for_year or DATEPART(YEAR, @EndDate) = @for_year)) THEN
DATEDIFF(DAY, @StartDate,@EndDate)
WHEN (@StartDate < cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (@EndDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
DATEDIFF(DAY, DATEADD(MONTH, DATEDIFF(MONTH, -1, @EndDate)-1, 0),@EndDate)
WHEN (@EndDate > cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) and (@StartDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
DATEDIFF(DAY, @StartDate,DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @StartDate) + 1, 0))) + 1
WHEN ((DATEDIFF(DAY, @StartDate, cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) >= 0) and (DATEDIFF(DAY, cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date), @EndDate) >= 0)) THEN
DATEDIFF(DAY, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime), DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime)) + 1, 0))) + 1
ELSE
0
END as [DD]
I don't know how you calculate day range between 01/01/2013 and 04/01/2013
is 4, it is actually is 3 but if that is the case, you can add 1 from the condition. -
How to make search between two dates accept null not obligatory search proplem
Hi guys when i search record between two dates it works ok success but you must enter date from and dateto first to to make search
i will show what i need from this example
I need to search dynamic by 4 textbox
1-datefrom
2-dateto
3-EmployeeNo
4-EmployeeName
but search i need must be dynamic meaning
if i enter employee no only give me employee no found in database
if i enter employee name give me employees found with this name using like
if i enter all 4 text box null and enter button search get all data
but i have proplem in this query when i need to search by click search button
i must write date from and date to firstly then write employee no or employee name if i need to search
so that i need to search by employee no alone or employee name alone without using date from and date to
And if i search without using datefrom and dateto it give me message error 'string wasnot recognized as valid datetime"
my stored procedure and code as following :
ALTER proc [dbo].[CollectsearchData]
@StartDate datetime,
@EndDate datetime,
@EmployeeID NVARCHAR(50),
@EmployeeName nvarchar(50)
as
Begin
Declare @SQLQuery as nvarchar(2000)
SET @SQLQuery ='SELECT * from ViewEmployeeTest Where (1=1)'
If (@StartDate is not NULL)
Set @SQLQuery = @SQLQuery + ' And (joindate >= '''+ Cast(@StartDate as varchar(100))+''')'
If (@EndDate is not NULL)
Set @SQLQuery = @SQLQuery + ' And (joindate <= '''+ Cast(@EndDate as varchar(100))+''')'
If @EmployeeID <>''
Set @SQLQuery = @SQLQuery + 'And (EmployeeID = '+ @EmployeeID+') '
If @EmployeeName Is Not Null
Set @SQLQuery = @SQLQuery + ' AND (DriverName LIKE
''%'+@EmployeeName+'%'') '
Print @sqlQuery
Exec (@SQLQuery)
End
Function using
public DataTable SearchDataA(string ConnectionString,string EmployeeNo,string EmployeeName, DateTime StartDate, DateTime EndDate)
SqlConnection con = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "CollectsearchData";//work
cmd.Parameters.Add("@StartDate", SqlDbType.DateTime);
cmd.Parameters.Add("@EndDate", SqlDbType.DateTime);
cmd.Parameters.Add("@EmployeeID", SqlDbType.NVarChar, 50);
cmd.Parameters.Add("@EmployeeName", SqlDbType.NVarChar, 50);
cmd.Parameters["@StartDate"].Value = StartDate;
cmd.Parameters["@EndDate"].Value = EndDate;
cmd.Parameters["@EmployeeID"].Value = EmployeeNo;
cmd.Parameters["@EmployeeName"].Value = EmployeeName;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
return dt;
interface button search
try
CultureInfo ukCulture = new CultureInfo("en-GB");
FleetManagment.Fleet fleet = new FleetManagment.Fleet();
DataTable Table = fleet.SearchDataA("Data Source=" + value1 + ";Initial Catalog=" + value2 + ";User ID=" + value3 + ";Password=" + value4 + "",textBox3.Text,textBox4.Text, DateTime.Parse(textBox1.Text,
ukCulture.DateTimeFormat), Convert.ToDateTime(textBox2.Text, ukCulture.DateTimeFormat));
dataGridView1.DataSource = Table;
dataGridView1.Refresh();
catch (Exception ex)
MessageBox.Show(ex + "error");Yes, the below code should not be passed any value: (I am not sure of the syntax in .NET,Sorry)
--If startdate len is 0 - do not assign this value
cmd.Parameters["@StartDate"].Value = StartDate;
--If endate len is 0 - do not assign this value
cmd.Parameters["@EndDate"].Value = EndDate; -
Hi,
I have table like this.
Id in_date value
2 05-Jun-08 5.3
3 08-Jun-08 5.2
4 08-Jun-08 5.3
5 08-Jun-08 5.8
6 10-Jun-08 7
7 10-Jun-08 5.6
8 11-Jun-08 2.6
When I query for average value between two dates, it should return average and if there is no entry for any dates it should return 0 for that date. Here is sample output for dates between 05-Jun-08 and 12-Jun-08.
In_date value
05-Jun-08 5.3
06-Jun-08 0.0
07-Jun-08 0.0
08-Jun-08 5.43
09-Jun-08 0
10-Jun-08 6.3
11-Jun-08 2.6
12-Jun-08 0
Please help me to write query on thisThanks,
SujnanSQL> with t as (
2 select 2 id,to_date('05-Jun-08','dd-mon-rr') in_date,5.3 val from dual union all
3 select 3,to_date('08-Jun-08','dd-mon-rr'),5.2 from dual union all
4 select 4,to_date('08-Jun-08','dd-mon-rr'),5.3 from dual union all
5 select 5,to_date('08-Jun-08','dd-mon-rr'),5.8 from dual union all
6 select 6,to_date('10-Jun-08','dd-mon-rr'),7 from dual union all
7 select 7,to_date('10-Jun-08','dd-mon-rr'),5.6 from dual union all
8 select 8,to_date('11-Jun-08','dd-mon-rr'),2.6 from dual
9 )
10 select t2.in_date,
11 nvl(t1.val,0) + t2.val val
12 from (
13 select in_date,
14 avg(val) val
15 from t
16 group by in_date
17 ) t1,
18 (
19 select min_in_date + level - 1 in_date,
20 0 val
21 from (
22 select min(in_date) min_in_date,
23 max(in_date) max_in_date
24 from t
25 )
26 connect by level <= max_in_date - min_in_date + 1
27 ) t2
28 where t2.in_date = t1.in_date(+)
29 order by t2.in_date
30 /
IN_DATE VAL
05-JUN-08 5.30
06-JUN-08 .00
07-JUN-08 .00
08-JUN-08 5.43
09-JUN-08 .00
10-JUN-08 6.30
11-JUN-08 2.60
7 rows selected.
SQL> SY. -
As to the data type of the data type of the difference between two date type of datas
Hi,
I have a question about the data type of the difference between two date type of datas.
There are two date type of datas as:
SSHIPMENTS.RECEIVEDATETIME
SSHIPMENTS.PROMISEDATETIME
I try to use the following SQL Script in Oracle SQL*Plus as:
SELECT CASE
WHEN (SSHIPMENTS.RECEIVEDATETIME - SSHIPMENTS.PROMISEDATETIME) < '000 01:00:00.000' THEN 'OnTime'
WHEN (SSHIPMENTS.RECEIVEDATETIME - SSHIPMENTS.PROMISEDATETIME) < '000 01:30:00.000' THEN '60-89 Minutes'
ELSE '3+ Hours'
END
FROM SSHIPMENTS;
The error message of "Invalid Number" for the '000 01:30:00.000' happens.
I don't know if the data type of the interval is wrong.
Many Thanks,
CathySELECT CASE
WHEN (to_char(SSHIPMENTS.RECEIVEDATETIME,'hhmiss') - to_char(SSHIPMENTS.PROMISEDATETIME,'hh24miss')) < '010000' THEN 'OnTime'
WHEN (to_char(SSHIPMENTS.RECEIVEDATETIME,'hhmiss') - to_char(SSHIPMENTS.PROMISEDATETIME,'hh24miss'))< '000 01:30:00.000' THEN '60-89 Minutes'
ELSE '3+ Hours'
END
FROM SSHIPMENTS;
just try it out.. -
Difference between two date ,according to office time.
hi,
How can I get diffrence between two date.
If I select from-date 20-03-2012 09:30AM and to-date 20-03-2012 06:30PM then output should be 1 day(as it is office time from 09:30 AM TO 06:30 PM).
ACCORDINGLY If I select from-date 20-03-2012 09:30AM and to-date 21-03-2012 02:00PM then output should be 1.5 day
select 24*(to_date(:P2_TO_DATE,'DD-MM-YYYY HH:MIPM') - to_date(:P2_FROM_DATE,'DD-MM-YYYY HH:MIPM'))"date" from dual;Hello Shirish,
WITH dates AS(
SELECT TO_DATE ('20-03-2012 09:30AM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('20-03-2012 06:30PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 09:30AM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('20-03-2012 04:15PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 09:30AM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('21-03-2012 02:00PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 09:30AM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('21-03-2012 12:00PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 04:30PM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('21-03-2012 02:00PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 04:30PM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('22-03-2012 02:00PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 04:30PM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('22-03-2012 10:00AM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
,times as(
SELECT start_date
,end_date
,TRUNC (end_date - start_date) days
,MOD (end_date - start_date,1) hours
,(start_date - 9.5/24 - TRUNC (start_date))*24 offset_start
,(end_date - 9.5/24 - TRUNC (end_date))*24 offset_end
,(end_date - 9.5/24 - TRUNC (end_date))*24
- (start_date - 9.5/24 - TRUNC (start_date))*24 offset_diff
FROM dates
SELECT TO_CHAR(start_date, 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_CHAR(end_date, 'DD-MM-YYYY HH:MIPM') AS end_date
,days
,ROUND(offset_start,2) offset_start
,ROUND(offset_end,2) offset_end
,ROUND(offset_diff,2) offset_diff
,CASE WHEN offset_diff > 4 THEN
days + 1
WHEN offset_diff > 0 THEN
days + 0.5
WHEN offset_diff = 0 THEN
days
WHEN offset_diff + 9 > 4 THEN
days + 1
ELSE
days + 0.5
END computed_days
FROM timesThe first step (subquery times) computes the full days and the difference between start_date and end_date, compared to the beginning of the office ours (9.5 /24)
The second step takes the days and according to the possible values of the difference adds a half or a full day.
Regards
Marcus
Edited by: Marwim on 19.03.2012 11:23
CASE offset_diff = 0 -
Date difference between two dates
hi All,
i have to right a stored proc to find the difference between two dates.
for example of i give
startdate as 4/1/2015 and enddate 14/1/2015
i should get 1 year , 10 days and 0 months .
i have tried the DateDiff function but it does not calculate the leap year.
please help.DECLARE @from datetime
DECLARE @to datetime
SET @from = '20150104 8:00'
SET @to = '20150114 10:30'
SELECT DATEDIFF(minute,@from, @to) % 60 as Minutes
SELECT (DATEDIFF(minute,@from, @to) / 60) % 24 as Hours
SELECT DATEDIFF(minute,@from, @to) / (60 * 24) as Days
SELECT DATEDIFF(month,@from, @to) as Months
SELECT DATEDIFF(year,@from, @to) as Year
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Difference between two date in bex query
Hi all,
I need to do a difference between two date using formula variable processing type customer exit beaucause I must use factory calendar in the formula.
How can I do it?
Can you give me an example of the routine?
Thanks a lot
GianmarcoHi,
You can still use the same code to copy it and customize as per your need. All you need to do is to subract the dates using the class: CL_ABAP_TSTMP after converting to timestamp and resulting seconds you convert back to days....Please get help from the developers to do this...
Also, ensure that you write back this difference value to your variable so you get it on the reports for your calculations...
Cheers,
Emmanuel. -
Using pl/sql function for each day between two dates.
Hi,
create TABLE EMP(
ID_EMP NUMBER,
DT_FROM DATE,
DT_TO DATE,
CREATE_DATE DATE);
into EMP(ID_EMP, DT_FROM, DT_TO, CREATE_DATE)
Values(100, TO_DATE('07/01/2008 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/30/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),TO_DATE('05/08/2009 14:11:21', 'MM/DD/YYYY HH24:MI:SS'));
I have a function called elig_pay_dates(date p_date), which returns the code for person payment eligibility for a particular date. For paid dates it's 'P' and for unpaid dates it's 'N'.
How can I check this function between two dates for each day. Example : 07/01/2008 to 04/30/2010.
By using this function with select I needs to display the dates when there is a change in status.
I am expecting data in following manner from above logic(this is example):
07/01/2008 --- 07/01/2009 ---'P'
07/02/2009 -- 07/25/2009 ----'N'
07/26/2009 -- 01/01/2010 ---'P'
01/02/2010 -- 01/13/2010 --'N'
01/14/2010 -- 01/18/2010 --'P'
01/19/2010 -- 04/30/2010 -- 'N'
I thought of looping for each day date but that seems to be expensive for online application. Is there any way that I can achieve this requirement with sql query ?
Thanks for your help,Certainly not the best way to code the requirement, but it does achieve the result you are looking for in a fairly quick time
create or replace
function test_ret_paid_unpaid (p_date in date)
return varchar2
is
v_ret varchar2(1);
begin
if ( (p_date between to_date('07/02/2009', 'MM/DD/YYYY') and to_date('07/25/2009', 'MM/DD/YYYY') ) or
(p_date between to_date('01/02/2010', 'MM/DD/YYYY') and to_date('01/13/2010', 'MM/DD/YYYY') ) or
(p_date between to_date('01/19/2010', 'MM/DD/YYYY') and to_date('04/30/2010', 'MM/DD/YYYY') )
then v_ret := 'N';
else
v_ret := 'Y';
end if;
return v_ret;
end;
Wrote file afiedt.buf
1 with get_paid_unpaid as
2 (
3 select dt_from start_date, dt_to end_date, dt_from + level - 1 curr_date, test_ret_paid_unpaid(dt_from + level - 1) paid_unpaid,
4 row_number() over (order by dt_from + level - 1) rn_start,
5 row_number() over (order by dt_from + level - 1 desc) rn_end
6 from test_emp
7 connect by level <= dt_to - dt_from + 1
8 ),
9 get_stop_date as
10 (
11 select start_date init_date, end_date, curr_date, paid_unpaid,
12 case when paid_unpaid != lag(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
13 then curr_date
14 else null
15 end start_date,
16 case when paid_unpaid != lead(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
17 then curr_date
18 else null
19 end stop_date
20 from get_paid_unpaid
21 )
22 select period, paid_unpaid
23 from (
24 select init_date, curr_date, start_date, end_date, stop_date,
25 case when paid_unpaid = lead(paid_unpaid) over (order by curr_date)
26 then nvl(start_date, init_date) || ' - ' || lead(stop_date, 1, end_date) over (order by curr_date)
27 else null
28 end period,
29 paid_unpaid
30 from get_stop_date
31 where stop_date is not null or start_date is not null
32 )
33* where period is not null
12:06:10 SQL> /
PERIOD PAID_UNPAID
01-JUL-08 - 01-JUL-09 Y
02-JUL-09 - 25-JUL-09 N
26-JUL-09 - 01-JAN-10 Y
02-JAN-10 - 13-JAN-10 N
14-JAN-10 - 18-JAN-10 Y
19-JAN-10 - 30-APR-10 N
6 rows selected.
Elapsed: 00:00:00.35 -
Determine posting to an asset between two dates
Hello all,
How do you calculate the postings made to an asset between two dates? I looked at the logical database ADA, but got lost in the source code.
For example, if these posting were made to an asset between start & end date, the total I would want would be $300.
Post $200
post $100
post $200
reserse the 2nd $200.
Thanks
BruceDear Friend,
Its very easy, simply execute transaction SQV and follow the below steps
Quick Viewer Screen appers
Create a new quick view
Give it a name, data source as table join, press enter.
Press Shift+F1, put the table name ANEK and press enter
Again press Shift+F1, put the table name as ANEP this time.
Press F3 or back button
Explode the Documnet Header and select List Filed and Selection Field check box for 1. Company Code 2. Main Asset Number, 3. Asset Sub Number,4. Fiscal Year, 5. Sequence Nuber, 6. Document Date or any other date on the basis of which you want to check the postings (e.g. posting date, entery date, asset valud date etc).
Press Execute button and enter.
A Report selection will appear, put the company code other parameters you have with you inclduing the date and execute again.
This will give you all posting between particular date.
Hope this solve your issue.
Thanks!!!
Murlidhar Khatri -
How can I calculate the maximum number of days between two dates in a range of dates?
I have a column of dates spanning the couse of a few months. I would like to know if I can calculate the maximum number of days between each row and display the highest number. I currently have another column that calculates the days betwen the rows and I am currently just looking at the totals and highlighting the highest period.
Is this possible? Any help or suggestions are appreciated.
Thank you,
TrevorThis sounds totally possible, Can you post a screen shot of your table to make responding more focused? If you mean you want to:
A) compute the difference (in days) between two date in the same row, then
B) find the max duration (in days)
Here is my take on this problem:
D2 = C2-B2
select D2 and fill down
F1=MAX(D)
to perform the conditional formatting (to highlight the max duration) select column D, then set up conditional formatting as shown in the 1st image -
How to calculate number of days between two date in Template design?
Hello guys
I have a situation where I have to create a template that returns data, and one of the thing of the existing report is that there is a column that is actually the number of days between start date and end date columns..
So in template, how would I be able to do the same? I have start date and end date columns on the template, now when I created another column using expression like end date - start date and preview the template, I am getting errors saying :
Caused by: oracle.xdo.parser.v2.XPathException: Cannot convert 03/31/2009 to number.
at oracle.xdo.parser.v2.XSLStylesheet.flushErrors(XSLStylesheet.java:1534)
at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:521)
at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:489)
at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:271)
at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:155)
at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:192)
Please advice
ThanksHi
There is an extension function you can use, from the javadoc:
date_diff
public static long date_diff(java.lang.String format,
java.lang.String fromDate,
java.lang.String toDate,
java.lang.String locStr,
java.lang.String tzID)
Method to get the difference between two dates in the given locale. The dates need to be in "yyyy-MM-dd" format. This function supports only Gregorian calendar.
Parameters:
format - the format to which the difference is required; allowed formats are y (for Year), m(for month), w(for week), d(for day), h(for hour), mi(for minute), s(for seconds) and ms(for milliseconds)
fromDate - the first date
toDate - the second date
locStr - locale string -> lang-Territory
tzID - timezone ID ->http://java.sun.com/j2se/1.4.2/docs/api/java/util/TimeZone.html
Returns:
the difference in dates in the desired format
For example
<?xdoxslt:date_diff(‘d’,’2009-09-14’, ‘2009-09-20’,’en-US’,1)?>
give a result of 6
You can substitute in columns for the dates, just remember the date format required.
Regards
Tim
Maybe you are looking for
-
My itunes library and ipod playlist disappeared?
i'm not sure what happened, but i intentionally deleted a bunch of mp3 files from my library (about 75% of my music folder) after uploading them to my 30 gig new generation Ipod. I believe that after this action, my Itunes library disappeared - inclu
-
HT5824 My find my phone is not working because I have a new number- same ID
I have a new number for my iPhone 5S, my icloud ID is still the same. My new phone can see my old phone, however, my comp can't see my new phone. I believe this because I have a new phone number. Everything else is working. My new phone is set to itu
-
Different effect in T-code VL32N and MIGO to do goods receipt
Dear gurus, What i wonder is when i do goods receipt in MIGO against Inbound delivery, the total goods movement status does not change to C-completely processed as expected, not like the effect when i use VL32N to post goods receipt. i spend long tim
-
Hi all I am executing the bapi BAPI_PO_CREATE. I have initialized the BAPI input fields and populated with necessary inputs. But when i execute the bapi, i get no output. Output should be available in Model node Return. But i get nothing. The bapi is
-
Inspection Plan & MIC status.
Dear SAP, We have a requirement that QC will creat the MIC & Inspection Plan in status created, and QA will review and change the status from Created to Release.So where or in which object level i can put control so that QC not able to select the Sta