Number of days difference

Here is my query, I am trying to find out number of days difference from Jan 1st that year to particular date of that year. Please let me know what wrong with that query?
SELECT TO_CHAR(30/06/2009,'DD/MM/YYYY') - (TO_CHAR('01-01-'||TO_CHAR(30/06/2009, 'YYYY'), 'DD/MM/YYYY')) + 1 from dual;Thanks for the help.

Hi,
Instead of playing guessing game with what error you are getting, it would have been much helpful if you state the error
Anyways, you cannot substract two char datatype, it should be a date datatype to substract.
select to_date(30/06/2009,'DD/MM/YYYY') - trunc(to_date(30/06/2009,'DD/MM/YYYY'),'YYYY')+ 1 from dualPS: Code is not tested. If found any error please post the error message too.
Regards
Anurag

Similar Messages

  • How do you work out the number of days difference between two dates?

    I'm running Crystal v12.
    We use a date field in our SQL database that we use to store the client's year end date.
    As the year end date (date and month) doesn't change for a client, the year end date field in all of our reports is set to just show the DD/MM part. Over the years as new clients are set up we just enter the date and month - the year part is irrelevant although as in all date fields the year is automatically entered.
    Doing it this way means that we don't have to adjust the year end year part each year. We just use the DD/MM part.
    I need to create a formula that works out the number of days there have been (i.e. the difference) from the current date to the year end date. It MUST EXCLUDE the year however.
    For example:
    Year End Date = 30/04/03
    Current Date = 25/05/10
    Days Difference (EXCLUDING year) = 25
    Days Difference (including year) = 2582
    Year End Date = 31/03/09
    Current Date = 25/05/09
    Days Difference (EXCLUDING year) = 55
    Days Difference (including year) = 420
    If you include the year part then working out day difference is simply a case of creating a formula that subtracts the year end date from the current date (CurrentDate - {tblClient.YearEnd}.
    HOWEVER I need to exclude the year part.
    Can anyone tell me the formula or best way to do this?
    Thanks in advance.
    Edited by: BadBoy House on May 25, 2010 3:15 PM
    Edited by: BadBoy House on May 25, 2010 3:15 PM

    Hi
    You can try this
    datevar e := date(year(currentdate),month({tblClient.YearEnd}),day({tblClient.YearEnd}));
    numbervar num_days := datediff("d",currentdate,e)
    Create a datevar called e that uses the original month and day numbers for {tblClient.YearEnd} but uses the year of the current date
    Then just datediff on e to get the number of days between the two dates
    I hope i understand your problem and that this helps
    Best regards
    Patrick

  • Number of Days with difference in 2 columns

    Dear all,
    Is this possible to display Number of Days with difference in 2 columns.
    Regards,

    Or use simply the ABS() function
    select abs(  date1 - date2 ) from dual ;Francois

  • 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

  • Conversion of Date into Number of Days

    Hai All,
               Can anyone pls tell how to convert the Date format into Number of days.
    For example I have 2 dates, 25.03.2009 and 25.02.2009.
    I have to take the difference of these two dates, means its 30 days.
    Later I have to move this 30 days to a variable and display.
    Can anyone help me.

    Try these FMs.
    CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
    EXPORTING
    i_datum_bis = p_sdate
    i_datum_von = p_edate
    IMPORTING
    e_tage = l_differ
    EXCEPTIONS
    days_method_not_defined = 1
    others = 2.
    WRITE:/ l_differ.
    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
    exporting
    i_date_from = p_sdate
    i_date_to = p_edate
    I_FLG_SEPARATE = ' '
    IMPORTING
    E_DAYS = EDAYS
    E_MONTHS = EMONTHS
    E_YEARS = EYEARS.
    WRITE:/ No of Days ', EDAYS.
    Regards,
    Joan

  • Determine the number of days in a False period in a Temporal Boolean

    Hi all,
    I need to determiine the number of days based on a condition that lies on the gaps between the periods.
    My input consists of multiple periods. The length of the gap is the condition to determine the start date for summation. However, there can be multimple gaps between my instances that satisfy this condition and I need the last one that satisfies it.
    For example:
    period 1: 1-1-1990 until 31-12-1992
    period 2: 1-1-1994 until 31-12-1996
    period 3: 1-1-1998 until 31-12-1999
    period 4: 1-6-2000 until 31-12-2009
    The condition for the start date is the last gap greater than 1 year. In this example, the start date should be the start date of period 3: 1-1-1998, because this is the period after the last gap >= 1 year. Period 2 also has a previous gap of >= 1 year, but this period should NOT be selected.
    My first idea was to use a TBR function: to determine relevant periods (based on the gaps before and after), calculate the amount of days per relevant period and add those up. However, if I want to do that I need to calculate the number of days in the gaps and I don't see how to do that, since I cannot determine a day difference across periods (end date period 1 until start date period 2).
    Any help/ other solution ideas?
    Kind regards, Els

    This was an interesting puzzle which you can solve from a couple of different angles.
    Firstly, you can use inferred relationships to infer a relationship "the following periods" (ie. the periods that follow the current one). My rules looked like this:
    the period (the other period) is a member of the following periods if
       the other period start date > the period start date
    the period’s next start date = InstanceMinimum(the following periods, the period start date)From here it should be easy to see if there was a gap of more than a year, and find the most recent period after a year-long gap. Of course you need to deal with the situation of the last period, when there is no 'next' period, presumably you would use the date of assessment in that case, but I'll leave that as an exercise for the reader.
    A completely different way of doing it is to use the TemporalConsecutiveDays function to find a date where a gap of 365 days exists, then select periods in which there is a gap immediately before the start of that period. Here are some rules that :
    there is a period that applies if
       ExistsScope(the periods)
          TemporalOnOrAfter(the period start date) and
          TemporalOnOrBefore(the period end date)
    there is a year-long gap if
       TemporalConsecutiveDays(365, 365, there is not a period that applies)
    the period starts after a year-long gap if
       ValueAt(the period start date, there is a year-long gap)
    the start date for calculation = InstanceMaximumIf(the periods, the period start date, the period starts after a year-long gap)Hopefully one of these is suitable for your needs.
    cheers,
    Steve.

  • 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,
    Trevor

    This 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
    Thanks

    Hi
    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

  • Function module which convert number to days to date

    Hi,
    Any one knows any function module which convert total number of days into date.
    thnaks,
    shilpa k

    Hi,
        FIMA_DAYS_AND_MONTHS_AND_YEARS
    FI_PSO_DAYS_MONTHS_YEARS_GET
    RSSM_CONVERT_DAYSEC2TIMESTAMP
    RSSM_CONVERT_TIMESTAMP2DAYSEC
    Function Modules related to Date and Time Calculations
    DATE_COMPUTE_DAY : Returns weekday for a date
    DATE_GET_WEEK : Returns week for a date
    DAY_ATTRIBUTES_GET : Returns attributes for a range of dates specified
    MONTHS_BETWEEN_TWO_DATES : To get the number of months between the two dates.
    END_OF_MONTH_DETERMINE_2 : Determines the End of a Month.
    HR_HK_DIFF_BT_2_DATES : Find the difference between two dates in years, months and days.
    FIMA_DAYS_AND_MONTHS_AND_YEARS : Find the difference between two dates in years, months and days.
    MONTH_NAMES_GET : Get the names of the month
    WEEK_GET_FIRST_DAY : Get the first day of the week
    HRGPBS_HESA_DATE_FORMAT : Format the date in dd/mm/yyyy format
    SD_CALC_DURATION_FROM_DATETIME : Find the difference between two date/time and report the difference in hours
    L_MC_TIME_DIFFERENCE : Find the time difference between two date/time
    HR_99S_INTERVAL_BETWEEN_DATES : Difference between two dates in days, weeks, months
    LAST_DAY_OF_MONTHS : Returns the last day of the month
    Regards

  • Calculation of number of Days?

    Hi Experts,
    i have two key figures one is calulate the number of day and the other is calulate the total number of stocks.
    So now my requirment is the user want to see the data like this,in report level.
    for Exp:
    if Number of days in between   10 -60 total stock is 100
    if Number of days in between    70- 80 total stock is 200
    if Number of days in between    81-130 total stock is 500.l  ike this.
    so how can i achieve this in query designer as i am using BI(7.0)?
    Regards,
    sat

    Hi ,
    Before posting a thread please provide the minimum info so that you can get the exact reply for your post.
    What are the data fileds that you have in your target to calculate the no of days?
    What is the source and IC on which you want to design the report?
    If u have any smaple data how you want the report to be? etc....
    If you have the date fields in your info provider then create 2 formula variable of type replacement path on both the date fileds.
    create a formula where use these two formula variables to get the difference of days.
    after that create one more formula and use
    ((diff of days>=10)AND(diff ofdays<=60)*Kf) will give you the stock value during that bucket.
    For more info plz refer to the below link which explains about the bucketing scenario.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/30f15839-0cf1-2b10-c6a7-ebe68cc87cdc?quicklink=index&overridelayout=true
    Regards
    KP

  • Number of days kept the material by sub contractor

    Dear Gurus,
    My requirement is how to calculate the number of days  for which the supplier has kept the material , till the last consumption, from the date of challan creation. idnt know how to calculate this, i searched a lot in google for finding this solution but no use,please help me.

    Hi Raajkumar,
    Wouldn't this be a difference between the posting date of movement 541 and the movement 543 for the components (or 101 of final assembly)?
    Best Regards,
    Tomek

  • Number of days issue

    Hello everyone,
    Here is my problem.  My user wants to have the number of days in a report based of an interval dates from posting date. 
    This is simple enough, i can just uses a formula variable to give the difference between the dates.
    But, if the user desided to drop in the posting period into the results rows, the user would like each period to show only the days in that period.
    So 01/05/2001 - 03/01/2001
    Would show a total 49
    If the user puts period in the results the user wants to see
    Period 1    Period 2     Period 3
    26             28          1
    Any ideas?
    Thanks!!

    Hi,
    It looks like your calculations doesn't depend on the date that the report is executed.
    Aren't you able then to calculate that differences on the data upload writing the result to a new key figure?
    If you have a record per each period then the solution is easy. If not... well then we'll have to think about another solution
    Hope it helps.
    Regards,
    David.

  • Number of days between two dates

    I have two dates-String Date1, String Date2(format of both the dates is 'DD-MM-YY'eg;'28-Jan-2008'). I want to find the difference between these dates;ie if value of String Date1 is '28-Jan-2008' and value of String Date2 is '28-Jan-2009', I need to find the number of days between these dates. What need to be done? Can anyone help me out please.
    Thanks in advance for all the help.
    Regards,
    Anees

    Doing a search is a bit ineffiecient. I'd take advantage of the fact that dates are acually stored in milliseconds. Subtract the two millisecond values (Data.getTime()) and divide by the number of milliseconds in a day. One complication, though, is daylight saving time but if you round rather than truncate in the division it should be fine.
    private static final long MILLIS_PER_DAY = 24L * 60L * 60L * 1000L;
    int dayDiff = (int)((date2.getTime() - date1.getTime() + MILLIS_PER_DAY/2)  / MILLIS_PER_DAY);

  • Number of days left

    Is it possible to show the number of days left from a date too 'sysdate' ? So as an example, if there was column with value of 'due_date' of 23/11/2013 and I wanted to see how may days there where left between SYSTDATE (today) and the 23/11/2013 (which would be two).. How can I do this as an SQL ?

    Hi,
    Sure:
    SELECT  DATE '2013-11-23' - TRUNC (SYSDATE)  AS days_left
    FROM    dual;
    If d1 and d2 are DATEs, then d1 - d2 is the NUMBER of days between them.  If d1 is earlier than d2, this will be a negative number.
    Remember, all DATEs in Oracle include hours, minutes and seconds.   In the query above, the hours, minutes and seconds are not specified in the DATE literal DATE '2013-11-23', so they default to 00:00:00.
    If SYSDATE is 00:00:00 on November 21, 2013, then the difference between that DATE and SYSDATE is exactly 2.000000.
    If SYSDATE is a minute or so after midnight on November 21, 2013, then the difference will be around 1.99.
    If SYSDATE is 06:00:00 on November 21, 2013, then the difference will be 1.75 days
    The query above, using TRUNC gives the differences as exactly 2 when SYSDATE is any time on November 21, 2013.
    Oracle calls this Date Arithmetic .
    For more, look up "date arithmetic" in the SQL Language manual:
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements001.htm#SQLRF00208

  • Confused - How to Calculate Number of Days Between Dates but Exclude Weekend Dates If There Hasn't Been a Weekend Update

    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,

Maybe you are looking for

  • Trying to watch on a folder on an network drive

    I store all of my photos on a netwrok drive so that everybody can acccess them.  Genrally the photos are imported and put up there by my wife using picassa on her laptop.  I am trying to watch this folder and find that PSE 10 organiser will not retai

  • Create table statement in a pl/sql procedure

    Hi all. I have a problem in Oracle 10g. First of all I must say that I'm new in oracle 10. I have a stored procedure in which I have the instruction "create table name_table as select col1,col2,col3,..ecc from table1, table2 where table1.col1 = table

  • Set default value for checkbox in XML definition

    Hi, I'ld like to set a default value to a checkbox (bound to UserDataSource) within the XML definition of my form. Is this possible, and if so, how?? I'ld also like to know if there is a description available of all possible tags/combination in XML b

  • JSP Worklist

              Hi,           I am trying to run the sample JSP Worklist that is downloadable from this site.           I use Web Logic 6.0 SP1           The first step says :           "Copy code into a directory $WEBLOGIC_HOME/myserver/public_html/workli

  • Namespace not define Error in IR when activate object..

    Hi, I am getting the name space not defined error when I try to activate the object in the IR even though I have defined the above namespace in this software component version. Could some body point me where I am missing.This might be a basic setting