How to substract two date&time values

Well,i just need to substract last visited date&time value from systemdate. The last visited date&time(from the filed named SONBULUNMAZAMANI, ) is selected from table (IHALE_KATILIMCILAR ) in the format DD-MM-RRRR HH24:MI and systemdate is in the same format. And i need to get value in minutes. Then i need to check if the value is greater then 20 minutes, finally i will update database and set IHALE_KATILIMCILAR.AKTIF=0. Here is the code i used;
DECLARE
MinDiff number;
DateTime1 ihale_katilimcilar.sonbulunmazamani%TYPE;
BEGIN
select t.sonbulunmazamani into DateTime1 from ihale_katilimcilar t where t.ihlkodu=141 and t.ihlaltktgkodu=132 and t.id_iliski=193;
MinDiff := ABS( TO_DATE( TO_CHAR(SYSDATE, 'DD-MM-RRRR') || TO_CHAR(SYSDATE , 'HH24:MI'), 'DD-MM-RRRR HH24:MI' ) - TO_DATE( TO_CHAR(DateTime1, 'DD-MM-RRRR') || TO_CHAR(DateTime1, 'HH24:MI'), 'DD-MM-RRRR HH24:MI' ) );
DBMS_OUTPUT.PUT_LINE('Difference is ' || MinDiff);
END;
However the result i get is always pointed values such as ,1895833333333333333333333333333333333333. How can i handle this?
And here is the scripts of table:
create table IHALE_KATILIMCILAR
KULADI VARCHAR2(20),
SONUC NUMBER(1),
AKTIF NUMBER(1) default 1,
SRKTKODU VARCHAR2(10) not null,
SONBULUNMAZAMANI DATE default sysdate,
SIRA NUMBER(1) default 0,
MESAJ VARCHAR2(200),
ID NUMBER(6) not null,
IHLKODU NUMBER not null,
IHLALTKTGKODU VARCHAR2(10) not null,
ID_ILISKI NUMBER,
IHLSIRA NUMBER(1) default 0,
CEVAP VARCHAR2(200)
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('asd', null, 1, '4444', to_date('19-02-2008 10:29:44', 'dd-mm-yyyy hh24:mi:ss'), 0, 'süre talep 2', 76, 145,
'135', 345, 0, 'al sna süre 77');
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('asd', null, 1, '4444', to_date('20-02-2008 14:49:52', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 77, 145, '135',
345, 0, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('asd', null, 1, '4444', to_date('19-02-2008 10:29:44', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 78, 145, '135',
345, 0, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('asd', null, 1, '4444', to_date('19-02-2008 10:29:44', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 79, 145, '135',
345, 0, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('KEMMM', null, 0, '42', to_date('17-03-2008 09:29:20', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 63, 141, '134',
191, 0, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('MLK', null, 1, '46', to_date('07-03-2008 09:52:20', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 64, 141, '134', 192,
0, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('KEM.ESM', null, 1, '44', to_date('06-03-2008 13:28:50', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 61, 145, '135',
189, 0, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('KE.ES', null, 1, '45', to_date('07-03-2008 11:16:41', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 69, 141, '133',
197, 0, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('KEMMM', null, 0, '42', to_date('17-03-2008 09:29:20', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 65, 141, '132',
193, 1, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('KE.ES', null, 1, '45', to_date('07-03-2008 11:16:41', 'dd-mm-yyyy hh24:mi:ss'), 2, null, 66, 141, '132',
194, 1, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('MLK', null, 1, '46', to_date('07-03-2008 09:52:20', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 67, 141, '132', 195,
1, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('KEMMM', null, 0, '42', to_date('17-03-2008 09:29:20', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 68, 141, '133',
196, 0, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('KEM.ESM', null, 1, '44', to_date('12-03-2008 15:00:58', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 70, 142, '252',
198, 1, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('KE.ES', null, 1, '45', to_date('10-03-2008 10:08:17', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 71, 142, '252',
199, 1, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('KEM.ESM', null, 1, '44', to_date('10-03-2008 10:08:56', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 72, 143, '253',
200, 1, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('MLK', null, 1, '46', to_date('12-02-2008 13:34:40', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 73, 143, '253', 201,
1, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('KE.ES', null, 1, '45', to_date('06-03-2008 14:09:40', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 60, 145, '136',
188, 1, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('KEM.ESM', null, 1, '44', to_date('06-03-2008 13:28:50', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 74, 145, '136',
202, 1, null);
insert into IHALE_KATILIMCILAR (KULADI, SONUC, AKTIF, SRKTKODU, SONBULUNMAZAMANI, SIRA, MESAJ, ID, IHLKODU,
IHLALTKTGKODU, ID_ILISKI, IHLSIRA, CEVAP)
values ('KE.ES', null, 1, '45', to_date('06-03-2008 14:09:40', 'dd-mm-yyyy hh24:mi:ss'), 0, null, 75, 145, '135',
203, 0, null);
Thanks...

What version of SQLServer do you have? Datediff is not an Oracle built-in function.
OP:
THe difference between two dates in Oracle is in days. The decimal portion refers to partial days, so you need to convert that to the required precision. Also, both sysdate and your column are date type, and contain a time portion, so you do not need all the to_date/to_char stuff. Something like:
SQL> SELECT end_dt, start_dt, (end_dt - start_dt) * 24*60 diff
  2  FROM (SELECT sysdate end_dt, TRUNC(sysdate) start_dt
  3        FROM dual);
END_DT             START_DT                 DIFF
17-mar-08 10:39:39 17-mar-08 00:00:00     639.65John

Similar Messages

  • How to get the date-time value?

    Hi All
    I have a a field "START_TIME of type DATE". The value stored for that particular field is of the form "10/17/2006 2:23:40 PM" i.e. a date-time value.
    Now when i try to get the values stored in the table in which the START_TIME field is defined i get the value in the form of "10/17/2006" .... I missed out the time information. Why is this so? How do i get the complete value as a string?
    Thanks in advance. Vijay

    Hi All
    I have a a field "START_TIME of type DATE". The value stored for that particular
    field is of the form "10/17/2006 2:23:40 PM" i.e. a date-time value.Actually it is stored as an internal date format (see my example SQL below, taking note of the dump'ed data).
    Now when i try to get the values stored in the table in which the START_TIME field is defined i get the
    value in the form of "10/17/2006" ....
    I missed out the time information. Why is this so?
    How do i get the complete value as a string?The value you see on the screen is the display format and this is determined by the client application that is displaying the date and what settings it is using. If a date column is retrieved from the database then all the data (date and time) is given back, but it's up to the application how that is displayed. e.g. you may see it differently if you view it is SQL*Plus against some other tool such as TOAD.
    To change the display settings you can change your NLS_DATE_FORMAT setting or whatever setting is suitable for your client application, or you can use TO_CHAR with a format string to specify the components you want to see. The different with TO_CHAR is that you are converting it to a character string so don't attempt to do any date type comparisons on it after that conversion, e.g. don't try and compare if one date is greater than another, without converting it back to DATE datatype first.
    SQL> create table t (x date);
    Table created.
    SQL> insert into t (x) values (sysdate);
    1 row created.
    SQL> select x from t;
    X
    02-JUN-08
    SQL> select x, dump(x) from t;
    X
    DUMP(X)
    02-JUN-08
    Typ=12 Len=7: 120,108,6,2,13,32,51
    SQL> alter session set nls_date_format = 'DD/MM/YYYY HH24:MI:SS';
    Session altered.
    SQL> select x, dump(x) from t;
    X
    DUMP(X)
    02/06/2008 12:31:50
    Typ=12 Len=7: 120,108,6,2,13,32,51
    SQL>

  • Date operations in java: how to substract two dates

    dear all
    I want to substract two date and return the number of days between them
    and I want to make a method that return the number of monthes between two dates
    please help

    Kayaman wrote:
    Check out the Calendar class.Hello Kayaman,
    From a quick glance at its API, I haven't found it obvious that Calendar could fulfill such need under 10-lines algorithms. As per Joda-time's proponents, it's one of those computation that are unintuitively hard or convoluted using the stock JDK date&time classes.
    If you're comfortable with Calendar, maybe you'd find it interesting to voice your opinion in this other topic: {thread:id=1982257}. Thanks in advance.
    Hello OP,
    apologies for plugging that discussion in your topic. But I do think it's closely related.
    I noticed you marked both replies as helpful. I'd like to know your feedback on those replies: have you tried both approaches, and succeed with one, or both? Have you met difficulties with either?
    Thanks, and good luck anyway.
    J.

  • Problem in storing date & Time value

    How to store the Date & time value in 1 textfield only.In my case i am selectecting The Time from two LOV's (HH & MM),then Date value is selecting from simple i/ptext,
    I want to store the (Date+HH+MM) in the date field.......
    code is....
    public String CalculationM() {
    BindingContainer bindings = getBindings();
    DCIteratorBinding dcIterBinding = (DCIteratorBinding)bindings.get("Timeview1Iterator");
    RowSetIterator row= dcIterBinding.getLovRowSetIterator();
    String i=selectOneChoice5.getValue().toString();
    int index=Integer.parseInt(i);
    int index2=index+1;
    Row r= row.getRowAtRangeIndex(index2);
    String val=r.getAttribute("Hour").toString();
    String i1=selectOneChoice6.getValue().toString();
    // System.out.println("HH index="+index2+" MM index is="+i1);
    int index1=Integer.parseInt(i1);
    int index3=index1+1;
    Row r1=row.getRowAtRangeIndex(index3);
    String val1=r1.getAttribute("Minutes").toString();
    int valint=Integer.parseInt(val);
    String valnew;
    if(valint<=12)
    {  if(valint==12)
    valnew=val+":"+val1+":"+"PM";
    else
    valnew=val+":"+val1+":"+"AM";
    else
    val=String.valueOf((valint-12));
    valnew=val+":"+val1+":"+"PM";
    valnew=val+val1;
    String Dateis= inputText4.getValue().toString();
    String Date1=Dateis+" "+valnew;
    System.out.println("TOTAl Date Is="+Date1);
    try
    { SimpleDateFormat sdf = new SimpleDateFormat("dd:MM:yyyy hh:mm");
    java.util.Date date = sdf.parse(Date1);
    java.sql.Date sqlDate = new java.sql.Date(date.getTime());
    oracle.jbo.domain.Date ojdd = new oracle.jbo.domain.Date(sqlDate);
    FacesContext context = FacesContext.getCurrentInstance();
    Application app = context.getApplication();
    DCBindingContainer binding = (DCBindingContainer) app.getVariableResolver().resolveVariable(context, "bindings");
    binding.findIteratorBinding("AppointDetView1Iterator").getCurrentRow().setAttribute(7,ojdd);
    catch(ParseException e)
    System.out.println("Error is:"+e.toString());
    OperationBinding operationBinding =bindings.getOperationBinding("Commit");
    Object result = operationBinding.execute();
    if (!operationBinding.getErrors().isEmpty()) {
    return null;
    return null;
    But i am getting error ....the Time is not storing in Date field bt the Time which we r giving with the Date field is storing.......
    My Date Attribute has Date format as dd-MM-yyyy hh:mm:aa
    If i changed it to dd-MM-yyyy then .... The value "12-3-2008" is not a valid date. Valid example: "29-11-2005 ".this error is getting
    Error
    - Not a date.
    Plz help me in this case ...wil be very thankful for ur help.........

    actually i am inputting the value 12-03-2008 but i am getting tha error which i hav told before....
    plz reply me....
    Message was edited by:
    user553181

  • How to substract two "HH:MM" varchar's

    Hi,
    I want to display HH:MM by substracting two varchar's of 'HH:MM".
    Eg:-
    Varchar1 --- 12:30
    Varchar2 --- 10:40
    O/p
    Diff --- 01:50
    how to substract two Varchars?

    ... and ... if you know the two times are supposed to be on the same day, but you're not sure which is the larger of the two you could do this to ensure you always get a positive answer...
    SQL> ed
    Wrote file afiedt.buf
      1  with table_x as (select '12:30' as v1, '10:40' as v2 from dual)
      2  --
      3  -- END OF TEST DATA
      4  --
      5  SELECT     TO_CHAR(TRUNC(SYSDATE) +
      6                   (GREATEST(TO_DATE (v1, 'HH24:MI'),TO_DATE (v2, 'HH24:MI')) -
      7                    LEAST(TO_DATE (v1, 'HH24:MI'),TO_DATE (v2, 'HH24:MI'))
      8                   ), 'HH24:MI')     AS diff
      9* FROM       table_x
    SQL> /
    DIFF
    01:50
    SQL> ed
    Wrote file afiedt.buf
      1  with table_x as (select '10:40' as v1, '12:30' as v2 from dual)
      2  --
      3  -- END OF TEST DATA
      4  --
      5  SELECT     TO_CHAR(TRUNC(SYSDATE) +
      6                   (GREATEST(TO_DATE (v1, 'HH24:MI'),TO_DATE (v2, 'HH24:MI')) -
      7                    LEAST(TO_DATE (v1, 'HH24:MI'),TO_DATE (v2, 'HH24:MI'))
      8                   ), 'HH24:MI')     AS diff
      9* FROM       table_x
    SQL> /
    DIFF
    01:50

  • How to dispaly System date time on Jsff page ?

    Friends,
    It would be simple question for you , Any one has idea about
    How to dispaly System date time on Jsff page using any expression laungage ?
    Thanks in Advance

    Hi,
    I have a solution for you I hope that is helps.
    add this to the top of your page...
    <jsp:useBean id="now" class="java.util.Date" scope="request" />
    so, you want the current date?
    <af:outputText value="#{now}"/>
    you can use the format for date also.
    I hope it is what you want.

  • How to Compare two Dates in java

    How to Compare two Date Field after getting the values from jTextField1.getText() and jTextField2.getText().

    Date d1=DateFormat.getDateInstance().parse(yourstring1);
    same for d2
    d1.compareTo(d2);
    could be that i misrememberd the exact naems of some functions or mixed up something in the equence of d1=

  • Calculate difference between two dates/times

    Hi all,
    Is there any function module to calculate difference between two dates/times which are in TIMESTAMPL format.
    I need to know how many millisconde(second,minutes, hours... )there is between these two times.
    Please, It is urgent
    Thank you all.
    Karim

    hi,
    try the following function
    CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'        
          EXPORTING                                  
               timestamp1 = timestamp1               
               timestamp2 = timestamp2               
          IMPORTING                                  
               difference = diff                     
          EXCEPTIONS                                 
               OTHERS     = 1. 
    the above function gives the difference in seconds...
    try the following  code to set the resolution to milliseconds..
    SET RUN TIME CLOCK RESOLUTION LOW
    check the thread for details:
    SET RUN TIME CLOCK RESOLUTION?
    all the best!!!
    Regards,
    Aparna

  • How can I display date+time and not the point number in excell?

    Hi everyone,
    Could anybody tell me how I can save date + time to a file, so that  I can display on a diagram(excel) : date+time in (ox) and data (oy)? :
    My program sets in (ox) the point number and not the date+time....( although  date and time are written correctly in the column...)
    Any help would be great,
    Thanks,
    regards,
    Marc

    hi there,
    excel uses 01.01.1900 00:00 as the time offset, LabVIEW uses 01.01.1904 02:00, so you can't display the correct datetime in excel when you write the time as a fractional number of seconds from LabVIEW. you must format the datetime in LabVIEW to a string and write that to the column. use the "Format Date/Time String" - function and for example "%d.%m.%Y %H:%M:%S%3u" as the format string (see the functions help for more examples). you also could format your data to a string using "Format Into String" - function and write the file as a 2D string array. the decimal point you have to use depends on your system and its settings, but you can specify the decimal point in the Format string like "%.;%f" (means fractional number with point as decimal point).
    best regards
    chris 
    Best regards
    chris
    CL(A)Dly bending G-Force with LabVIEW
    famous last words: "oh my god, it is full of stars!"

  • How do I get a time value in days, hours and minutes returned to a cell from a calculation of distance divided by speed?

    How do I get a time value in days, hours and minutes returned to a cell from a calculation of distance divided by speed?

    Simon,
    you can use the duration function:
    B4=DURATION(0,0,B1/B2)
    you can further, format the cell as a duration like this using the cell inspector:

  • How to get the date time format in OCI

    How to get a date time format in OCI instead of only date

    You would have to use the OCIDateTime datatype for this. Refer to
    OCI documentation for more details.

  • How to execute two structure type values

    How to execute two structure type values for HWC app in SUP 2,2 ? Added is the screenshot, with the structure and values to be executed. Trying in the preview works fine , but how to process in the application ?

    Thanks Midhun VP i came across result checker , but still checking if there is any work around without result checker. , Will  a HTML view with some Success status work in this scenario .
    Correct me if i am wrong, as per my understanding , Result checkers checks the error code return value from BAPI and shows the respective message.
    If so, what are the Pros and Cons of using Result checker.
    Is it suggested to use Result checker for read only operations applications i,e which does nt involve operations( CUD)

  • When retrieving a 'date time' value, why is there a '.0' appended?

    Hi
    I am storing 'date time' values in a MySQL 'DATETIME' column.
    I retrieve the value by executing code (more or less) like this:
    ResultSet resultSet = statement.executeQuery(query);
    // other statements here...
    String theDate = resultSet.getString(i);If the 'date time' being stored is *2008-08-26 16:39:21*, the code returns this: *2008-08-26 16:39:21.0*
    Is there same 'simple' way to retrieve the value without a *.0* appended?
    Thanks
    Pete

    Hi Roy
    I'm not quite with you.
    You should get it from the database as a date object.Do you mean something like this?:
    ResultSet.getDate()This returns a java.sql.Date object.
    For presentation use SimpleDateFormatter to display it the way you want toI presume you are referring to java.text.SimpleDateFormat ? In that case I require the date as a java.util.Date object.
    Perhaps you could clarify a bit more?
    Thanks
    Pete

  • Invalid date/time value error

    I downloaded a trial version of Acrobat XI Pro when I try to save or edit and resave a document I get 'invalid date/time value', error.  I presume it's set for the US and not the UK, can you tell me where I can change the date/time format?
    I'm running on Windows 7

    Hi Rave
    Susan's on leave at the moment so I'm replying on her behalf in the vain hope we can sort things before she gets back and before the trial period runs out!  I'm not sure I understand what you mean by column of date and time - we have a review date in the Word document before we pdf but that's all.  Yes we are saving to a sharepoint server.
    Thanks

  • The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.

    The below function is giving me the hours difference what I wanted, but today it is giving us the below error: 
    Msg 535, Level 16, State 0, Line 1
    The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.
    Please Help..
    ALTER FUNCTION [dbo].[GetHoursExcludingWeekdays](@StartDate datetime2,@EndDate datetime2)
    returns decimal(12,3)
    as
    begin
        if datepart(weekday,@StartDate) = 1
            set @StartDate = dateadd(day,datediff(day,0,@StartDate),1)
        if datepart(weekday,@StartDate) = 7
            set @StartDate = dateadd(day,datediff(day,0,@StartDate),2)
        -- if @EndDate happens on the weekend, set to previous Saturday 12AM
        -- to count all of Friday's hours
        if datepart(weekday,@EndDate) = 1
            set @EndDate = dateadd(day,datediff(day,0,@EndDate),-2)
        if datepart(weekday,@EndDate) = 7
            set @EndDate = dateadd(day,datediff(day,0,@EndDate),-1)
        declare @return decimal(12,3)
        set @return = ((datediff(second,@StartDate,@EndDate)/60.0/60.0) - (datediff(week,@StartDate,@EndDate)*48))
        return @return
    end
    ReportingServices

    You'll get this error if the difference between the start and end date is greater that about 68 years due to the "second" DATEDIFF specification.  Perhaps the dates are greater than the expected range due to a data quality issue. 
    Taking the advice from the error message, you could use minutes instead of seconds like the example below the version below.  This could still result in the error of the difference is greater than a couple of hundred years, though.  You might consider
    validating the dates and returning NULL if outside expected limits.
    ALTER FUNCTION [dbo].[GetHoursExcludingWeekdays](@StartDate datetime2,@EndDate datetime2)
    returns decimal(12,3)
    as
    begin
    if datepart(weekday,@StartDate) = 1
    set @StartDate = dateadd(day,datediff(day,0,@StartDate),1)
    if datepart(weekday,@StartDate) = 7
    set @StartDate = dateadd(day,datediff(day,0,@StartDate),2)
    -- if @EndDate happens on the weekend, set to previous Saturday 12AM
    -- to count all of Friday's hours
    if datepart(weekday,@EndDate) = 1
    set @EndDate = dateadd(day,datediff(day,0,@EndDate),-2)
    if datepart(weekday,@EndDate) = 7
    set @EndDate = dateadd(day,datediff(day,0,@EndDate),-1)
    declare @return decimal(12,3)
    set @return = ((datediff(minute,@StartDate,@EndDate)/60.0) - (datediff(week,@StartDate,@EndDate)*48))
    return @return
    end
    GO
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

Maybe you are looking for