Subtract two dates to get months and days
I havew to subtract two dates and get the differnce ,
Date issuedDate= myobj.getIssueDate();
Date expirationDate=DateUtils.addMonths(issuedDate, 6);
long timeDiff=expirationDate.getTime()-new Date().getTime();
long daysRemaning=timeDiff/86400000;this is code I get the number of days between the issue date and todays date.now my client wants not just days but months and days , i need suggestions on how to get days and months between any two given dates
I have read that it is best to use java.util.Calendar for almost any time related issue.
With some switch statements and a for loop, I think the Calendar class could solve the problem.
Similar Messages
-
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. -
Any F.Module is there to get 'Month and day ' from the given input number
Hi experts,
I am working on Inventory withdrawl report and in the selection screen, If i enter the CHARG (Batch number) then I need to display the posting date by default in the next selection input based on the Batch number.
In the selection screen :
Batch : 7111WF0211.
Posting Date : (I need to display by default based on batch number).
My requirement is, in the above Batch first digit '7' is the year.
And from 2nd to 4th digit. i.e., 111. I need to find out month and day from 111.
I mean from 1 to 365 days, In which day and which month '111' will come ?
Please send me the code or suitable Function Module. Your help will be appreciated.
Thanks,
Ranji.Use FM ADD_TIME_TO_DATE
Do this
days = batch+1(3).
days = days - 1.
Call Function 'ADD_TIME_TO_DATE'
exporting
i_idate = '01.01.2008'
i_time = days
i_iprkz = 'D'
importing
o_idate = date_p_d
You will get the date in date_p_d.
But what about Leap years? IS the first number the year?
IF so pass in i_idate the first of january of that year so you get the correct day depending if it is a leap year or not
Edited by: Ramiro Escamilla on Feb 26, 2008 9:56 PM -
Date separate year, month and day
Hello everyone and thanks in advance, I'm new to this and the truth is not doing this.
Well, I have a PDF with several pages which I designed and has been asking me in a complete date in the format dd / mm / yy and subsequent pages he asks me the same date of birth but in 3 separate fields, day , month and year. I want you when you enter the date the first copy and separate day month and year in others. I tried this but I get
var array_datesol = datesol.split("/")
var year = parseInt(array_datesol[2]);
var month = parseInt(array_datesoll[1]);
var day = parseInt(array_datesol[0]);
this.getField('yearsol').value = year;
this.getField('monthsol').value = month;
this.getField('daysol').value = day;
where is the initial field datesol date and year, month and day where they have to be separately
thanks in advanceAre you getting any errors in the JavaScript debugging console?
You are using the syntax for the 'Custom JavaScript calculation' and this syntax can not be used in the 'simplified field notation. Also you can not use any JavaScript properties, objects, functions, control statments.
When run in the console, I find you have a misspelling of the variable name 'datesol'. I also do not see where you are initializing the value for 'datesol'.
var datesol = event.valueAsString; // get value of this field
var array_datesol = datesol.split("/") ; // make into an array
this.getField('yearsol').value =array_datesol[2]; // get element year
this.getField('monthsol').value = array_datesol[1]; // get month element - fixed variable name
this.getField('daysol').value = array_datesol[0]; // get date element
I would use one of the following so the other fields are only updated when a date has been entered and the leading zeros are displayed:
this.getField('yearsol').value = '';
this.getField('monthsol').value = '';
this.getField('daysol').value = '';
if(event.value != '') {
// get parts of date and print with leading zeros
var datesol = event.value; // get value of this field
var array_datesol = datesol.split('/') ; // make into an array
this.getField('yearsol').value = util.printf('%,304.0f', array_datesol[2]); // get element year
this.getField('monthsol').value = util.printf('%,302.0f', array_datesol[1]); // get month element - fixed variable name
this.getField('daysol').value = util.printf('%,302.0f', array_datesol[0]); // get date element
// or
this.getField('yearsol').value = '';
this.getField('monthsol').value = '';
this.getField('daysol').value = '';
if (event.value != '') {
// get date parts and print with leading zeros
var oDatesol = util.scand('dd/mm/yyyy', event.value); // get date object
this.getField('yearsol').value = util.printf('%,302.0f',oDatesol.getFullYear()); // get element year
this.getField('monthsol').value = util.printf('%,302.0f', oDatesol.getMonth() + 1); // get month element - fixed variable name
this.getField('daysol').value = util.printf('%,302.0f', oDatesol.getDate()); // get date element
// or
this.getField('yearsol').value = '';
this.getField('monthsol').value = '';
this.getField('daysol').value = '';
if(event.vaue != '') {
// get parts of date and format
var oDatesol = util.scand('dd/mm/yyyy', event.value); // get date object
this.getField('yearsol').value = util.printd('yyyy', oDatesol); // get element year
this.getField('monthsol').value = util.printd('mm', oDatesol); // get month element - fixed variable name
this.getField('daysol').value = util.printd('dd', oDatesol); // get date element
If you are going to fill other field, you will need to use the '.valueAsStriing' property or '.toString()' method to retain the leading zeros. -
Get Months and Days -- Problem with months_between
Hi,
For a report, I need to convert days as months and days for eg 370 days as 12 months 5 days.
I tried below query
with t as (
select
maturity_date - value_date tenor
from account_master)
select
trunc(mod(months_between(trunc(sysdate,'YYYY')+ tenor,trunc(sysdate,'YYYY')),30)) month,
(trunc(sysdate,'YYYY')+tenor)-add_months(trunc(sysdate,'YYYY'),trunc(months_between(trunc(sysdate,'YYYY')+ tenor,trunc(sysdate,'YYYY')))) "day"
from t
And i am getting output as
MONTH day
11 30
23 30
11 30
1 5
11 30
11 30
11 30
0 6
11 30
for Number of days
TENOR
365
730
365
36
365
365
365
6
365
As you can see for 365 days i am getting Months as 11 and days as 30
and for 730 days i am getting months as 23 and days as 30.
I want 365 days as 12 months and 0 days.
I think it is months_between function that is creating this problem.
Can anyone suggest another way of accomplishing this?
Thanks and Regards
Amit Trivedi2008 is a leap year! so it's 366 days long. therefore, 365 days is really only 11 months and 30 days (if you start counting from Jan 01, which is what you are doing).
so the number of months and days between is dependent on the starting date (consider a range of 30 days starting on Jan 01, Feb 01 (leap year), Feb 01 (non-leap year) and Apr 01).
so:
with t as (
select maturity_date - value_date tenor, value_date d1 from account_master
select
trunc(months_between(d1+ tenor,d1)) months,
d1+tenor - add_months(d1,trunc(months_between(d1+ tenor,d1),30)) days
from t
or better yet:
select
trunc(months_between(maturity_date,value_date)) months,
maturity_date - add_months(value_date,trunc(months_between(maturity_date,value_Date))) days
from account_master
/ -
FM to get the number of days in Year,month and days by giving number of day
Hi ALL,
This is quit differnt.
I need to give input the 'start date' and the 'number of days' and get the total days from the start date in year,month and day format.
for example.
start date :01.01.2009
number of days as 32
then i should get
years:0
months :1
days :1
Pleas help me out.hi Anusha,
first u pass the date and the days to the following fm you will get the result date....
data:date type sy-datum,
r_date(10) type c.
date = sy-datum.
CALL FUNCTION 'CALCULATE_DATE'
EXPORTING
DAYS = '32'
MONTHS = '0'
START_DATE = date
IMPORTING
RESULT_DATE = r_date
write:/ r_date.
then you need to pass the result date and the date to the following fm to get the required output...
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
date1 = r_date
date2 = date
IMPORTING
years = v_years
months = v_months
days = v_days
EXCEPTIONS
invalid_dates_specified = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
here u will get the difference in days, months and year...
i hope u wil get help from this...
regards
Ashu Singh -
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"); -
What is the formula to find the months and days between dates
Tricky... The first problem is the intended result. Months have a varying number of days in them, days and weeks have set values. For example the difference between 1st July and 1st September is 2 months but this does not give an accurate count of the number of days (61).
It would be better to calculate the number of days difference and forget the months.
You would need a lookup table showing a numeric value for each date that would show each date with a day value from a starting point. If your earliest date is 01/01/2000 then that would be day zero. Then using the lookup table calculate the day value for your beginning and end dates. Subtract one from the other to get the number of days.
If all your dates are from this year:
You can create your own Cell Format (call it day of the year) Select the Type: Date & Time
drag the icon for Day of Year into the box and delete the others.
Convert your dates to this new Format, subtract one value from the other to get the number of days difference. -
To find months and days between 2 dates
Hi,
I want to find the months and days between 2 dates.
For Eg.
Date-1 : 25-Aug-2013
Date-2 : 23-Oct-2013
If we consider every month as 30 days it should give
25-Aug-2013 to 30-Aug-2013 = 6 days
01-Sep-2013 to 30-Sep-2013 = 1 Month
23-Oct-2013 to 30-Oct-2013 = 8 days
Total = 1 month and 14 days.
Kindly help at the earliest.
Thanks & Regards
SureshSureshM wrote:
Hi,
I want to find the months and days between 2 dates.
For Eg.
Date-1 : 25-Aug-2013
Date-2 : 23-Oct-2013
If we consider every month as 30 days it should give
25-Aug-2013 to 30-Aug-2013 = 6 days
01-Sep-2013 to 30-Sep-2013 = 1 Month
23-Oct-2013 to 30-Oct-2013 = 8 days
Total = 1 month and 14 days.
Kindly help at the earliest.
Thanks & Regards
Suresh
That's not a good idea though. Be considering every month as 30 days, then comparisons over larger date ranges (years) will be out by more and more days the larger the difference gets.
Your example is also wrong.
For Eg.
Date-1 : 25-Aug-2013
Date-2 : 23-Oct-2013
If we consider every month as 30 days it should give
25-Aug-2013 to 30-Aug-2013 = 6 days
01-Sep-2013 to 30-Sep-2013 = 1 Month
23-Oct-2013 to 30-Oct-2013 = 8 days
The last one should be:
01-Oct-2013 to 23-Oct-2013 = 23 days
giving a result of 1 month and 29 days.
Oracle provides a months_between function to do the calculation.
SQL> select months_between(date '2013-10-23', date '2013-08-25') from dual;
MONTHS_BETWEEN(DATE'2013-10-23',DATE'2013-08-25')
1.93548387
But of course, because the number of days in a month varies, it's not exacly known what the decimal part of the number represents.
However, if you combine methods, using months_between to get the months, and then assume 30 days for a month to get the days part from the remainder, it's more consistent over longer periods...
SQL> ed
Wrote file afiedt.buf
1 with dates as (select date '2013-08-25' as date_from, date '2013-10-23' as date_to from dual)
2 --
3 select months_between(date_to, date_from)
4 ,trunc(months_between(date_to, date_from)) as months
5 ,round(mod(months_between(date_to, date_from),1)*30) as days
6* from dates
SQL> /
MONTHS_BETWEEN(DATE_TO,DATE_FROM) MONTHS DAYS
1.93548387 1 28 -
Using Adobe Acrobat Pro XI and Excel 14.3.8 on a mac.
Saved PDF as "optimized PDF" then "save as other" > spreadsheet > Microsoft Excel Workbook.
Problem: numbers in some random dates are transposed so that month and day are reversed. No particular pattern to these errors. Only fix we've found is to go through and manually check and correct the date errors - there are hundreds of these errors in the document so this is not a good solution.
(Note: Excel columns with dates are specified as "date" fields. All dates are formatted as m/d/yy)
Any ideas what's causing this problem problem and how to fix it?
Thanks in advance![discussion moved to Creating, Editing & Exporting PDFs forum]
-
Convert Fiscal Period to Month and day in HR/FI
HI Experts,
i am dealing now with an issue in HR for actual and plan Data.
I have two cubes one for actual and one for plan. The actual cube is just using the satndard BI extractor and the plan cube is loaded per flatfile with fiscal/year Period.
We are working with Fiscal/year period.
Now we want to create a report where we can see both the result in Month and day.
I would like to know how to implement it to get the correct result.
Could you please help me on that way?
Thank you.
GiloSolved by myself.
-
I'm trying to calculate the number of days until your next birthday. Only using current month, day and birth month and day. I can get close but i'm way off. When i enter in the next day, the amount of days is supposed to be 364. This is where I am having problems. I know my code is way off. I just need some guidance please!
Attachments:
D5.7_1.vi 8 KBI just had a little fun with the Time Record...
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
D5.7_1_BD.png 19 KB -
Leading zeros for Month and Day in filename.
Hello,
I am in Jdev 10.1.3.3.0
One of my requirement is to have a file name concatenated with current month and day (example: <filename><02><23>).
Used the xpath as following and returns an output as *'filename223'*:
concat('filename',xp20:month-from-dateTime(ora:getCurrentDate()),xp20:day-from-dateTime(ora:getCurrentDate()),'.txt')
what changes I need to make in my Xpath to get the file name as *'filename0223'*
Thanks in advance!
Regards,
RakeshI was googling on the date format used in BPEL to achieve various format types. Specially I was searching for my requirement : <filename><current month with leading zeros if month is single digit><current day with leading zeros if day is single digit>(ie. if the month is february and day is 23rd, then my filename should be *<filename><02><23>*).
I found a link which helped solving my problem :
http://plane.javaeye.com/blog/161316
I changed my Xpath to :
concat('filename',xp20:format-dateTime(ora:getCurrentDate(),'[M01][D01]'),'.txt')
And I got my expected result : *'filename0223.txt'*
Regards,
Rakesh -
Convert days to months and days?
Hi,
I need to take a a numeric value like 280 (which is really the number of days) and convert it to the number of months and days (eg 9 months and 10 days). Is this possible with PowerShell?
Thanks
Adam$ht = @{Months=$days/30;Days=$days%30}
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
G
... rubbishell code ( from #2 ).
I tested your rubbishell code, and got bad result:
PS Q:\> $days=299 ; $ht = @{Months=$days/30;Days=$days%30} ; $ht
Name Value
Days 29
Months 9,96666666666667
Do you really think 9,9666... is an integral number?
No, it's not.
If you wanna know the correct values, just look above at my last reply.
I didn't realize you don't know how to truncate decimal.
$ht = @{Months=[int](($days/30)-.5);Days=$days%30}
But you did put together that convoluted mess to get the equivalent of a simple modulo operation, so that probably should have been a clue.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
GREAT!
... rubbishell code ( from #2 ).
I tested your rubbishell code ONCE MORE(!), and got bad result
ONCE MORE(!):
PS Q:\> $days=300 ; $ht = @{Months=[int](($days/30)-.5);Days=$days%30} ; $ht
Name Value
Days 0
Months 10
Do you really think 10 is equal to 11?
Don't you think the correct answer is 11?
If you wanna know the correct values, just look above at my last reply.
Give it up dude, you'd better copy and paste my PowerShell code. :)
No, I'm pretty sure 300 days at 30 days/month is 10 months.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " " -
Difference between 2 dates in form of years,months and days.
Hi friends,
i need one function module for finding difference between 2 dates and the output is
no. of years
no.of months
no. of days.
it means the input is begin date and end date
output is no.of years,no.of months and no.of days.
for example begin date is today i.e., 08/02/2008 (dd/mm/yyyy) and end date is 07/03/2008 then the output is
no.of years -
0,
no.of months----
1,
no.of days----
0.
and one more example if begin date 08/02/2008
(dd/mm/yyyy) and end date is 01/02/2008 then the output is
no.of years -
0,
no.of months----
0,
no.of days----
-7..
Please help me it's very urgentHi,
Use FM HR_AUPBS_MONTH_DAY.
It Calculate the years, months, days & cal days between 2 dates.
Hi,
The FM is 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
Check the following example:
DATA: EDAYS LIKE VTBBEWE-ATAGE,
EMONTHS LIKE VTBBEWE-ATAGE,
EYEARS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
exporting
i_date_from = FROMDATE
i_date_to = TODATE
I_FLG_SEPARATE = ' '
IMPORTING
E_DAYS = EDAYS
E_MONTHS = EMONTHS
E_YEARS = EYEARS.
WRITE:/ 'Difference in Days ', EDAYS.
WRITE:/ 'Difference in Months ', EMONTHS.
WRITE:/ 'Difference in Years ', EYEARS.
INITIALIZATION.
FROMDATE = SY-DATUM - 60.
Also You can write your own function module for this..
just extract day and month and year from the two dates and then get the difference.
suppose date 1 - y1m1d1
date 2 = y2m2d2
data : y1(2) type n,
m1(2) type n,
d1(2) type n,
y2(2) type n,
m2(2) type n,
d2(2) type n,
y1 = date1(4).
m1 = date1+4(2).
d1 = date1+6(2).
y2 = date2(4).
m2 = date2+4(2).
d2 = date2+6(2).
then get the differnce between years and days and months and store them in ur variables
Reward Points if found helpfull..
Cheers,
Chandra Sekhar.
Maybe you are looking for
-
Non-functional Java Control Panel Refuses to Disable Updates
Hope this is the right place to post! I cannot disable updates for Java, nor change any options inside the Java Control Panel. I make changes, click OK or Apply, open it back up and find they are all unchanged. This is on Vista Home Premium, SP2, Adm
-
Hi all, i'm in the process of making a fairly generic ELS functionality with by using eInsight Correlation. Have one inbound Queue that is being picked up by a JMS Receive, initialized the CorrelationSet, etcetera. Then goes on to a while loop which
-
Hi guys, Please any one can send me the SD (Over to Cost) structures.
-
Hi My macbook has started getting really hot after using it for only maybe 10 minutes or so, it can go up to 73 degrees quite quickly, I am only surfing the net etc but have a few pages open at the same time. Also should I switch it off after I finis
-
I can't get itunes to recognize my iPad 2.