How to calucate days between 2 date
for example
I want to get diff between '17-apr-2007' and '03-apr-2007'
You can use add_months function,
add_months(Date1, -date2);
Make sure one date is with -ve signNo, you cannot
SQL> select add_months(sysdate, -(sysdate-3)) diff from dual;
select add_months(sysdate, -(sysdate-3)) diff from dual
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got DATECheck out the SQL reference what add_months is used for
http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/functions5a.htm
Similar Messages
-
How to get days between two dates
Hi ,
How to get days between two dates.
Regards,
Ramesh.Hi Ramesh,
REPORT ZDATEDIFF.
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. -
How to calculate days between two DATES
How to calculate days between two DATES ?
which is the functional module for that ?
help meHi,
use function module : it works,
HR_HK_DIFF_BT_2_DATES
give output format = 03 and get the value in days.
code is as below :
data : DATE1 type P0001-BEGDA,
DATE2 type P0001-BEGDA,
YEARS type P0347-SCRYY,
MONTHS type P0347-SCRMM,
DAYS type P0347-SCRDD.
date1 = '20070331'.
date2 = '20070101'.
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
DATE1 = date1
DATE2 = date2
OUTPUT_FORMAT = '03'
IMPORTING
YEARS = years
MONTHS = months
DAYS = 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.
write : days.
Reward points, if helpful,
Regards,
Sandeep Kaushik -
How to count the days between Date Range using OO ABAP?
hi experts,
i want to count the days between Date Range using OO ABAP for that which class and method can i use?.
Thanks,
Mahesh.Not sure I understand the requirement for it to be OO, but you could always write your own (i.e. use this):
REPORT zz_date_diff.
CLASS date_diff DEFINITION.
PUBLIC SECTION.
METHODS diff IMPORTING i_date_fm TYPE d
i_date_to TYPE d
EXPORTING e_days TYPE i.
ENDCLASS."
CLASS date_diff IMPLEMENTATION.
METHOD diff.
e_days = i_date_to - i_date_fm.
ENDMETHOD."
ENDCLASS."
DATA: g_ref TYPE REF TO date_diff,
g_days TYPE i,
g_date_fm TYPE d VALUE '20080101',
g_date_to TYPE d VALUE '20090101'.
START-OF-SELECTION.
CREATE OBJECT g_ref.
CALL METHOD g_ref->diff
EXPORTING
i_date_fm = g_date_fm
i_date_to = g_date_to
IMPORTING
e_days = g_days.
WRITE g_days. -
Hello -
I've been tearing my hair out over this problem i'm trying to solve, probably just been staring at it too long which is making it worse -
I have a series of open support tickets which are supposed to be updated on a daily basis, the problem is that they aren't always being updated daily. So, the business wants to know the number of days from when a ticket was last updated and today's
date. I have this basic calculation and it's working fine, however now the business wants to exclude weekends from the calculation. The other problem is that some reps DO go in on weekends and update their tickets, so sometimes there will be updates
made on weekend dates.
To give an example -
Today's date is 2014-02-10 (Monday). A ticket was last updated last Thursday, 2014-01-30. The difference between the two dates is 11, so it's been 11 days since the ticket was last updated. Now, if I exclude Saturdays and Sundays, then
it's actually been 7 days since the ticket was last updated. I'm not sure how to do this in T-SQL.
Now, to further complicate the problem, sometimes a ticket IS updated on a Saturday or Sunday. So, if a ticket was updated on 2014-02-02 (Sunday), then it should be counted. Again i'm not sure how to do this.
What gets me is that this is probably fairly simple and i've just been staring at it too long. In the meantime, can someone offer some guidance?
Thanks!!I've adapted this from a function on my blog. you will need to add set the YourTicketTable to where ever your tickets are stored.
CREATE
FUNCTION [dbo].[CalcWorkDaysBetween](@StartDate
As DateTime,@EndDate
AS DateTime)
RETURNS
INT AS
BEGIN
SET @EndDate
=DATEADD(DAY,1,@EndDate)
DECLARE @Count
AS Int= 0
DECLARE @Date
As Date=@StartDate
WHILE @Date
< @EndDate
BEGIN
IF (DATEPART(WEEKDAY,@Date)IN(1,7)
OR (SELECT
Count(*)
FROM YourTicketTable WHERE TicketDate=@Date)=1)
BEGIN
SELECT @Count = @Count
+ 1
END
SELECT @Date=DATEADD(Day,
1,@Date)
END
RETURN
DATEDIFF(DAY,@StartDate,@EndDate)- @Count
END
Regards, -
How to retrieve day between two dates?
Hi all,
Hope doing well,
sir i am retrieving day between two dates in sql server like this.
select datediff(day,'2012-10-03 00:00:00.000','2012-10-05 00:00:00.000')
and getting result that is: 2
but how this type of query i'll use in oracle?
thanks,Just do minus
diff := date_variable2-date_variable1;The difference sill be in days.
If you want just the differences in days (Neglecting time part)
diff := trunc(date2)-trunc(date1); -
How to calculate days between 2 dates excluding public holidays over SAP ?
Hi
Have a universe over SAP data. Trying to calculate days between 2 dates. SAP holds Public Holiday data in various tables e.g Thol and data is updated via scal. Using my univeres as a source I want to run reports for different countries so need to have various bank holidays not just UK. In SAP function modules handle this. Has anyone designed a solution to cater for this situation in a universe ?
Thanks in advance
MHi,
I assume you mean SAP R/3 (ECC) when you write SAP and SAP BW.
Are you using BW? If so, I would load the data into SAP BW, create a query using customer exit variables and build your universe on top of that...
-J -
How to get days between 2 dates in jasperreports
hi All
i m not getting how to find days b/w 2 dates in jasper reports.....
here is da detail info....
i am generating jasper reports for transaction in bank
i have to get the days b/w current transaction and last transaction dats way its needed
plz any one help me to get days b/w current and previous transactions...
i m waiting for ur respone....plz.
with regards
kotreshtake a look at Calendar in the API docs.
It should give you some ideas.
If it doesn't, look harder as the answer is right there. -
How to count days between two dates excluding saterady and sunday
Hi all
iam working on oracle sql/plsql.
In my application , i need to caliculate leave days between two dates excluding saterady and sunday
Please tell me the solution if any one knows
thanks in advance ,
baluMore modern version:
WITH date_tab AS
(SELECT TO_DATE ('&from_date', 'dd-MON-yyyy')
+ LEVEL
- 1 business_date
FROM DUAL
CONNECT BY LEVEL <=
TO_DATE ('&to_date', 'dd-MON-yyyy')
- TO_DATE ('&from_date', 'dd-MON-yyyy')
+ 1)
SELECT business_date
FROM date_tab
WHERE TO_CHAR (business_date, 'DY') NOT IN ('SAT', 'SUN');Thank you,
Tony Miller
Webster, TX
Never Surrender Dreams!
JMS
If this question is answered, please mark the thread as closed and assign points where earned.. -
Find year,month & day between dates
Hi,
I need to find a number of years, months & day between a given dates. For example If a employee joined on 31.01.2003 and left on 01.06.2006, I need to find in between how many years, months & days he has worked. Is there any function module available .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.
Using teh abiove u can get difference but when u pass previous year u wont get the exact.
There is no seperate FM for this, u have to use three FM.
If possible using these three FM code u can create an FM.
<b>For years and months between two days:</b>
DATA: EYEARS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE PREL-BEGDA,
TODATE LIKE PREL-BEGDA DEFAULT SY-DATUM.
CALL FUNCTION 'COMPUTE_YEARS_BETWEEN_DATES'
EXPORTING
first_date = fromdate
* MODIFY_INTERVAL = ' '
second_date = todate
IMPORTING
YEARS_BETWEEN_DATES = EYEARS
* EXCEPTIONS
* SEQUENCE_OF_DATES_NOT_VALID = 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.
Write:/ eyears.
DATA: EMONTHS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE SY-DATUM,
TODATE LIKE SY-DATUM
DEFAULT SY-DATUM.
CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
EXPORTING
i_datum_bis = fromdate
i_datum_von = todate
* I_KZ_INCL_BIS = ' '
IMPORTING
E_MONATE = emonths
write:/ emonths
CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
I_DATUM_BIS = x_faede-zfbdt
I_DATUM_VON = p_fdat
I_KZ_EXCL_VON = '0'
I_KZ_INCL_BIS = '0'
I_KZ_ULT_BIS = ' '
I_KZ_ULT_VON = ' '
I_STGMETH = '0'
I_SZBMETH = '1'
IMPORTING
E_TAGE = dias_v.
IF SY-SUBRC <> 0.
ENDIF.
x_faede-zfbdt -> 20050915
p_fdat -> 20050811
dias_v = 4
try this and let me know.
Message was edited by:
Judith Jessie Selvi -
Find no. of days between dates
Hi guys,
I have 5 dates with me, 2 of which are Key Figures and 3 are of Char. date type. Now, I have to find no. of days between these dates using various permutation and combination i.e. it can be between 2 KF's or 2 Char. types or 1 KF and 1 Char. type as well.
1) I think finding no. of days between 2 KFs can be done using Cumulative KF.
2) I tried to find no. of days between 2 Charac. by creating a Formula (2 variables with Replacement Path) and then finding the difference. But the output seems to be wrong.
eg. 27.02.2009 - 19.01.2009 = 108 days, which is wrong!
(Posting date) (clearing date)
3) I also have to do it between 1 KF and 1 Char. date type, tried creating 1 variable for Char. and then subtracting with KF, but Report shows 'X' in the output!
Any suggestions?
Thanks.Hi,
You can do it by using Customer Exits and Replacement path Variables..
see teh floowing thread.
Difference in days
Thanks
Reddy -
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. -
hi friends.
I want to find out days in date.
is there is any method or FM to find out days in date.
thanks in advance.
regards.
Bhaskar.Hi,
do like this.
data:v_dat like sy-datum,
v_daytext like HRVSCHED-DAYTXT,
v_out(20) type c.
v_dat = sy-datum.
CALL FUNCTION 'RH_GET_DATE_DAYNAME'
EXPORTING
langu = sy-langu
date = v_dat
CALID =
IMPORTING
DAYNR =
DAYTXT = v_daytext
DAYFREE =
EXCEPTIONS
NO_LANGU = 1
NO_DATE = 2
NO_DAYTXT_FOR_LANGU = 3
INVALID_DATE = 4
OTHERS = 5
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
else.
v_out = v_daytext.
ENDIF.
write:/ v_out.
for more information go to se37 and check the function module.
do reward points if it helps you.
Regards,
Sowjanya. -
How to give space between date mm and year in terms of bytes
Hi Guru,
In sapscript I want to give space in datae formate betweeen day and month , month and year in terms of bytes.
Example :
if datae is 2009/08/18 then I want to move like 2009 08 18. Here the gap between the date field and month , year fields is in terms of bytes. Like 4 bytes gap between year and date, 5bbytes gap between day and month in ECC6.0.
Please help in this.
Thanks,
PJ.hii prakash,
Use the Function Module.
RP_FORMATING_DATE
If you use this FM then automatically it will convert it to YYY MM DD format and then you can use as per your requirement
or you can do like this
Use following code to change the date format from DD.MM.YYYY to YYYY MM DD
DATA : DATE(10) TYPE C,
DATE1(10) TYPE C.
CONCATENATE DATE6(4) DATE3(2) DATE+0(2)
INTO DATE1
SEPARATED BY ' '.
regards,
Shweta
Edited by: Shweta Joon on Aug 18, 2009 10:38 AM -
How to calculate difference between date in hours?
Hi All.
I need calculate difference between first and last date. I'm using the code below:
int differenceDate = CalendarRule.elapsedDays(fromDate : myFirstDate, toDate : myLastDate);
This code return an result in days. But I need that result was in hours.
Has anybody help me?Interval dif;
dif = myLastDate - myfirstDate;
display((dif.hours));
Hope it helps
Maybe you are looking for
-
Importing a 900 page MS-Word document to InDesign CS 6
The Word document has course descriptions of all the classes offered at a community college. The need is to have two columns(textboxes of equal size) in each page of the InDesign document and then bring the information from the Word document to InDes
-
Hi sir, i am struggling in mid of init without data transfer, after deletion of setuptable i have init with out datatransfer, and the request is in yellow since from long time,, i think due to because of no data and if i scheduled the delta without r
-
Studio 8 doesn't run on Windows 7 [subject edited by moderator]
On a Windows 7 machine, my Studio 8, an upgrade from MX2004 which includes DW-8 no longer works, error msg. states registration problem "reinstall software". Tried everything to fix this issue. Flash 8 (part of Studio 8 works fine) Re-installed MX20
-
Color matching in Illustrator with CMYK
This is a technical question about the best practice to follow when trying to match a color with Illustrator. A short description of what I'm trying to do is in order. I have a digital printer which uses an Epson 2880 print head and driver. I ha
-
I installed Maverick, now I can't open iPhotos V9.2.3. What can I do?