Skip to Content
avatar image
Former Member

Date_diff function for days

I should calculate the number of days between two dates. To do that I used Date_diff function, however noticed this function returns one day less than it should return. For example :

Date_Diff ('2011.11.16', '2011.11.17') = 0

It should be 1, I can just add 1 to the result to work around it, but would like to see why DS behaves like this.

Have you faced with this issue? Any idea why?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Nov 29, 2010 at 04:01 PM

    I just tested the function and it works fine, however you need to include the format string parameter so the function knows you want the different in days.

    $TextString = Date_Diff ('2011.11.16', '2011.11.17','D') ;

    print($TextString);

    The result will be 1.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Joseph Mismas

      Yes you were right. It was a problem in conversion to date. I was ignoring warnings about it. The conversion to date type should have been done as:

      TO_DATE(TO_CHAR(REFERRAL_DIM.REFERRAL_DATE_TIME,'YYYY.MM.DD'), 'YYYY.MM.DD')

      Thanks for your help.

  • avatar image
    Former Member
    Nov 29, 2010 at 02:01 AM

    The formula works perfectly fine... you can do the debugging on the generated program where you can see the difference is getting calculated..

    Add comment
    10|10000 characters needed characters exceeded