How to get date difference in terms of years,months and also days
Tool : Eclipse
Framework : JSF & Springs
JRE : jdk1.5.0_06
Iam using oracle 10G DB as back end.I have two date fields in a table.
1)premium_paying_start_date
2)premium_paying_end_date
Iam getting these two dates from the database and storing these values within a entity.Now in the delegate layer,
i have to get the premium_term i.e, the difference between the two dates(premium_paying_end_date-premium_paying_start_date).
The difference should show the year,month and no of days difference.
For example :
premium_paying_start_date : 14-10-1984
premium_paying_end_date : 01-03-2008
Difference should be : 23 Y : 4 M : 15 D (Y = years, M = months , D= days)
So please give me the solution for this.
Difference should be : 23 Y : 4 M : 15 D (Y = years, M = months , D= days)
So please give me the solution for this.How did you determine what the difference should be?
~
Similar Messages
-
Convert two dates difference to number of years, months and days
Post Author: gigimonu
CA Forum: Formula
I wanted to write a formula (if there is a function I can use) that can convert a date difference to total number of years, months and days example
adate = 10/22/2006
?xdate = current date - adate (answer should be 1 years, 0 months and 0 days)
Please help
ThanksPost Author: V361
CA Forum: Formula
[Years, Months, Days]
DATEVAR FROMDATE := DATE(2000,01,01); // FROM DATE
DATEVAR TODATE := CURRENTDATE; // TO DATE
NUMBERVAR YEARS;
NUMBERVAR MONTHS;
NUMBERVAR DAYS;
STRINGVAR DIFF;
DATEVAR TEMP;
IF TODATE < FROMDATE THEN
(TEMP := TODATE;
TODATE := FROMDATE;
FROMDATE := TEMP);
YEARS := DATEDIFF('YYYY',FROMDATE,TODATE);
IF YEARS > 2 THEN
(YEARS := YEARS - 2;
TEMP := DATE(DATEADD("M",YEARS * 12,FROMDATE));)
ELSE
(YEARS := 0;
TEMP := FROMDATE);
WHILE TRUE DO
(TEMP := DATE(DATEADD('M',1,TEMP));
IF TEMP > TODATE THEN
EXIT WHILE;
MONTHS := MONTHS + 1);
DAYS := DATEDIFF('D',DATE(DATEADD('M',-1,TEMP)),TODATE);
IF MONTHS > 12 THEN
(YEARS := YEARS + INT(MONTHS/12);
MONTHS := MONTHS MOD 12);
DIFF := IIF(YEARS>0 ,TRIM(TOTEXT(YEARS,0)) & " YEARS " ,"0 YEARS ") &
IIF(MONTHS>0,TRIM(TOTEXT(MONTHS,0))& " MONTHS ","0 MONTHS ")&
IIF(DAYS>0 ,TRIM(TOTEXT(DAYS,0)) & " DAYS" ,"0 DAYS"); -
How to convert days to years, months and remaining days
Hi All,
I have the number of days for example : 398 days how to
convert 398 days to number of years and number of months and remaining days
like 398 days 1 year , 1 month and 2 days
Regards
rkraoe.g.
SQL> select sysdate, sysdate - 1234 from dual
2 /
SYSDATE SYSDATE-1
09-AUG-06 24-MAR-03
SQL> select trunc(trunc(months_between (sysdate, sysdate - 1234))/12) yrs,
2 mod(trunc(months_between(sysdate, sysdate - 1234)), 12) mnths,
3 sysdate - add_months((sysdate - 1234), trunc(months_between(sysdate, sysdate - 1234))) dys
4 from dual
5 /
YRS MNTHS DYS
3 4 16
SQL> -
How to get date difference in data sources
Hi,
In SQL:SELECT DATEDIFF(day, '2005-12-30 23:59:59.9999999', '2005-12-30 00:00:00.0000000');
output :1
As similar way how get the datediffence in SAP business by design of the datasources.
Regards,
PrasadHi Prasad,
For this you have to create a Custom DATA SOURCE for the required BO. Then Select all the required fields that you want to use it in the report for that datasource.
The 3rd step of Data Source Wizard is shown in the image, here you can add a extra field that can hold the difference between the DateTime elements present in the BO.
In the left column BUSINESS OBJECT ELEMENT choose DATE element (1st Date).
In the right column TRANSFORMATION choose DateTime To Duration row and in the PARAMETER Column choose the field against which you want to calculate the difference.
In Defined Field Name enter a name, this will hold the value of the calculated difference.
Thank You
Shabaz -
How to get Date Difference in Query with Replacement Path !
I need to get nr of days between two days. I knew that we can do this by replacement path in the queries. But when Iam trying to use replacement path with
this two chars and put it in a formula the result is not showing correctly.
Eg: I have dates Date1, Date 2 and I created two variables calles DateA ,Date B with reference to Date1 and Date2.
Now Iam creating a formula sayint that (Date2 <> 0) * (Date1 - Date2) ...Here Date2 has sometimes balnk value...Iam getting the values when there is dates for both chars...But if there is one value is blank
then Iam getting a strange value ....
can any body send me step by step on how to fix this...
ThanksHi Sam,
another important think you have to remember when having aggregated information is to divide the date1 and date2 key figures with the number of lines used in aggregation.
Remember that date1 (internally) is a numerical value from some initial date which is used as reference. E.g., if the reference date is 01/01/0001 and you have the date 15/01/0001 then key fig. date1 internally stores just the value 14. So if you have something like:
date1 date2 diff
customer1 material1 14 18 4 <- correct
customer2 material1 14 18 4 <- correct
and then you make an aggregation by removing customer from your report then you will have the following situation:
date1 date2 diff
material1 28 36 8 <- wrong
So, you would have to divide by 2 in the second case. Please try to check the above and proceed accordingly. Let us now if something else weird appears.
Best regards,
Theodoros -
How to get data occured on less than 12 months gap, please
Hello Good Afternoon,
How can i get ssns that are occured in less than 12 month period
create table #mytemp (SSN varchar(9), planID vcarchar(8), period varchar(7))
Insert Into #mytemp values ('123456789', '200R1','2013-04')
Insert Into #mytemp values ('123456789', '200R5','2014-09')
Insert Into #mytemp values ('123456789', '200R1','2012-05')
Insert Into #mytemp values ('123456789', '200R3','2013-11')
Insert Into #mytemp values ('123456789', '200R1','2014-01')
Insert Into #mytemp values ('213456789', '400R1','2014-04')
Insert Into #mytemp values ('213456789', '400R5','2014-09')
Insert Into #mytemp values ('213456789', '400R1','2013-05')
Insert Into #mytemp values ('213456786', '700R5','2014-05')
Insert Into #mytemp values ('213456786', '400R1','2013-05')
Insert Into #mytemp values ('215556786', '400P1','2013-05')
i am trying to get the below two results
1) How to find out the duplicate SSN's that were having period of less than 12 month difference
2) How to find out the duplicate SSN's that were having period of less than 12 month difference with same planID
Please Help me
expected results for Query 1
create table #ans1 (SSN varchar(9))
Insert Into #ans1 values ('123456789') --- had more than one record in 12 month span
Insert Into #ans1 values ('213456789') -- had more than one record in 12 month span
expected results for Query 2
create table #ans2 (SSN varchar(9))
Insert Into #ans2 values ('123456789') --- had more than one record in 12 month span for plan 200R1
Please help me here with your valuable advise
Thank you in Advance
Milan1) How to find out the duplicate SSN's that were having period of less than 12 month difference
2) How to find out the duplicate SSN's that were having period of less than 12 month difference with same planID
Below is one method. The second query also returns '213456789' because your sample data has more than one row for planID 400R1 within 12 months.
SELECT DISTINCT
a.SSN
FROM #mytemp AS a
WHERE EXISTS ( SELECT *
FROM #mytemp AS b
WHERE b.SSN = a.SSN
AND CAST(b.period + '-01' AS date) > CAST(a.period
+ '-01' AS date)
AND CAST(b.period + '-01' AS date) < DATEADD(YEAR, 1,
CAST(a.period
+ '-01' AS date)) );
SELECT DISTINCT
a.SSN
FROM #mytemp AS a
WHERE EXISTS ( SELECT *
FROM #mytemp AS b
WHERE b.SSN = a.SSN
AND b.planID = a.planID
AND CAST(b.period + '-01' AS date) > CAST(a.period
+ '-01' AS date)
AND CAST(b.period + '-01' AS date) < DATEADD(YEAR, 1,
CAST(a.period
+ '-01' AS date)) );
Dan Guzman, SQL Server MVP, http://www.dbdelta.com -
How to get data from media files such author, title and so on
Hi you all!
You'd have to parse the binary file header yourself. JMF doesn't have any built-in ways to extract META data from media files.
Also, don't post your question in the title and not in the body of the message. It's annoying and stupid... -
How to get all open sales orders of a customer and also account group
I want to know the logic to find all open sales orders of a customer and also account group
Hi,
You can check the status weather a Sales order is Open or not by checking its billing status form the following:
Check table VBUK and VBUP for delivery status "LFSTK" and billing status "FKSTK".
Rward points if helpful answer.
Ashven -
How to compare data in a single table by month and year
Hello Please.,
i would like to see the 2014-06 matched results (3rd query),
if the same ssn and acctno is exist in 2012-06 and 2013-06 and 2014-06 then eliminate from results, otherwise show it
select ssn, acctno From jnj.drgSamples where Channel ='KM' and TrailMonth ='2012-06'
select ssn, acctno From jnj.drgSamples where Channel ='KM' and TrailMonth ='2013-06'
select ssn, acctno From jnj.drgSamples where Channel ='KM' and TrailMonth ='2014-06'
i have written the below query but it shows only matched across three queries, but i want to display / delete from 2014-06 records if the ssn and acctno is exist in 2012-06 and 2013-06
select c.* from (
(select * From jnj.drgSamples where Channel ='KM' and TrailMonth ='2012-06' ) a join
(select * From jnj.drgSamples where Channel ='KM' and TrailMonth ='2013-06' ) b on a.SSN = b.SSN and a.acctno = b.acctno join
(select * From jnj.drgSamples where Channel ='KM' and TrailMonth ='2014-06' ) C on a.SSN = c.SSN and a.acctno = c.acctno join
Please Help me with this
Thank you very much in Advance
AsittiThis is a relational division problem T-SQL:
Relational Division
Try:
;with cte as (select ssn, acctno, count (distinct(TrailMonth)) as cntMonths
from jnj.drgSamples WHERE Channel = 'KM' AND TrailMonth IN ('2012-06','2013-06',2014-06'))
GROUP BY ssn, acctno)
delete from jnj.drgSamples S where exists (select 1 from cte where S.ssn = cte.ssn and S.acctno = cte.acctno and cte.cntMonths = 3)
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
How to get the difference of two dates in years,months and days
Hi friends,
how to get the difference of two dates in years,months and days
for ex 2 years 3 months 13 days
select (sysdate-date_Start) from per_periods_of_service
thanksSomething like this...
SQL> ed
Wrote file afiedt.buf
1 with t as (select to_date('17-nov-2006','dd-mon-yyyy') as c_start_date, to_date('21-jan-2008','dd-mon-yyyy') as c_end_date from dual union all
2 select to_date('21-nov-2006','dd-mon-yyyy'), to_date('17-feb-2008','dd-mon-yyyy') from dual union all
3 select to_date('21-jun-2006','dd-mon-yyyy'), to_date('17-jul-2008','dd-mon-yyyy') from dual
4 )
5 -- end of test data
6 select c_start_date, c_end_date
7 ,trunc(months_between(c_end_date, c_start_date) / 12) as yrs
8 ,trunc(mod(months_between(c_end_date, c_start_date), 12)) as mnths
9 ,trunc(c_end_date - add_months(c_start_date, trunc(months_between(c_end_date, c_start_date)))) as dys
10* from t
SQL> /
C_START_D C_END_DAT YRS MNTHS DYS
17-NOV-06 21-JAN-08 1 2 4
21-NOV-06 17-FEB-08 1 2 27
21-JUN-06 17-JUL-08 2 0 26
SQL>But, don't forget that different months have different numbers of days, and leap years can effect it too. -
How to get the difference of two dates?
let's say i have a table named tblData and has 4 columns: data_RefNo, data_DateReported, data_TargetDate, data_Data
tblData returns 2 rows.
data_RefNo.............data_DateReported.............data_TargetDate........................data_Data
10000................10-20-2004 10:55:44 AM........10-20-2004 10:57:44 AM........Slow Response Time
10000................10-21-2004 10:55:44 AM........10-21-2004 11:55:44 AM........Bug Error
i just wana ask how to get the difference of the date_DateReported and date_TargetDate.
i tried this code but it didnot work
public Vector get_con_pf()
Vector vData = new Vector();
String query = "SELECT * FROM tblData WHERE data_RefNo= '"'10000'"'";
try
DBConnect db = new DBConnect();
db.openCon();
ResultSet rs = db.execute(query);
while (rs.next())
vData.addElement(DATEDIFF(mi, rs.getString("st_DateReported"), rs.getString("st_TargetFinishDate")));
db.closeCon();
catch (Exception e)
System.out.println("Error: " + e );
return vData;
i want to return the difference of the data_DateReported and date_TargetDate, i did this
vData.addElement(DATEDIFF(mi, rs.getString("st_DateReported"), rs.getString("st_TargetFinishDate")));but it didnot work.
How do i get that? because i want to return a vector.
the code must return the values:
2 for the 1st rows because the difference is only 2 minutes, and
60 for the 2nd row.ooops i tried this one:
query = "SELECT *, DATEDIFF(mi, data_DateReported, data_TargetDate) AS diff FROM tblData WHERE data_RefNo = '10000'";and it works.
hehehehe!!!!!!
problem solved! :) -
Get Date Difference between 2 date values as days
Hi,
How to get the difference between 2 dates in number of days format. Say if i need the difference between 2012-08-23 and 2012-08-20 as 3
Please help..Hi,
You can do it in XSLT since the dates are in ISO 8601 format...
http://www.w3.org/TR/NOTE-datetime
Here is a sample XSLT...
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:template match="/">
<xsl:variable name="date1" select="xs:dateTime(/root/date1)"/>
<xsl:variable name="date2" select="xs:dateTime(/root/date2)"/>
<xsl:value-of select="fn:days-from-duration($date2 - $date1)"/>
</xsl:template>
</xsl:stylesheet>The above XSLT will result *4* for the following input...
<root>
<date1>2012-01-11T00:00:00.000-05:00</date1>
<date2>2012-01-15T00:00:00.000-05:00</date2>
</root>You can test this example here...
http://xslttest.appspot.com/
Hope this helps...
Cheers,
Vlad
It is considered good etiquette to reward answerers with points (as "helpful" - 5 pts - or "correct" - 10pts)
https://forums.oracle.com/forums/ann.jspa?annID=893 -
How to get Date Format from Local Object.
Hi All,
I am new to Web Channel.
I need to know Date format From date of locale.
suppose there is a date "01/25/2010" date in date field I want to get string "mm/dd/yyyy". Actually I have to pass date format to backend when I call RFC.
Is there any way to get Date format from "Locale" object. I should get date format for local object
I get local object from "UserSessionData" object but how to get Date format from it.
I am not looking for Date value. I am looking for current local date format ("mm/dd/yyyy or dd/mm/yyyy or mon/dd/yyyy) whatever local date format. I could not find example which show how to get date format from "Locale" object.
Any help will be appreciated with rewards.
Regards.
Web ChannelHi,
You can get it from "User" or "Shop" business object.
Try to get User or Shop Business Object as shown below.
BusinessObjectManager bom = (BusinessObjectManager) userSessionData.getBOM(BusinessObjectManager.ISACORE_BOM);
User user = bom.getUser();
char decimalNotation = user.getDecimalPointFormat().getGroupingSeparator();
If you are seeing "1,234.00" then above code will return "."
I hope this information help you to resolve your issue.
eCommerce Developer. -
How to get data from a USB-UIRT device using Labview?
How to get data from a USB-UIRT device using Labview?
I'm trying to get data from a USB-UIRT device, is it posible with Labview?
I really appreciate your help,
thanksYou may want to contact the developer of the device for the API and DLL.
http://65.36.202.170/phpBB2/viewforum.php?f=3 -
How to get data type of variable in program..
Hi ABAP Guru.
I need to know how to get data type of variable or any structure field.. because I got short dump when use command REPLACE ALL OCCURANCE ... with variable/structure field that has data type I or P, I think it should be used with data type CHAR only, So I need to check the data type first.
Please give me your advice
Thank you all.
Nattapash C.data : v_value type i,
v_char(10) type c.
v_value = 10.
move v_value to v_char.
REPLACE ALL OCCURRENCES of '#' from v_char....
Best regards,
Prashant
Maybe you are looking for
-
Apps won't open, or crash after launch
OK so I updated to OS X 10.9.1 and since then, my Adobe Apps won't open, or they crash after launch. Photoshop CC for instance opens, then immediately crashes with a crash report. On the other hand, Illustrator simply doesn't even open. No crash repo
-
My iMac will not boot into the Apple Hard Ware test. Why is this?
I have a late 2012 27 inch iMac. It will not boot into the Apple Hard Ware test. I do have File Vault turned on. Will this stop it from booting in to the test?
-
Message mapping: table lookup
The requirement: Source message contains some keys and values, and target message has different keys. Values are simply mapped. no problem. but the mapping between source message keys and target message keys is a bit complicated so it is controlled i
-
If someone gives me a jpeg they want edited, and I take it into lightroom and then edit it, how to I exprt it the same size that they sent? Can I create an export action that allows the same size file to be exported each time? Thanks! Sarah
-
Help in ECC 6.0 - Enhancements and Modification with BADI
Hi, I want <b>Enhancements and Modification help in ecc 6.0 and BADI also</b>.. Plz tell me as soon as possible.... Regards, <b>Anil Kumar</b>