6 Replies Latest reply: Jun 13, 2013 7:24 AM by Selvakumar S

# Difference between two Dates

Hi All,

I need to find the difference between two dates. For this i used this expression below

(

dayStart(timestamp(END)) - dayStart(timestamp(START)))

but how to include the Start and end date also while subtracting

For Example:

START Date: 24-Feb-2013  and END Date: 2-Mar-2013

If i used the above expression, Result is : 6

But i need the result as 7 (24,25,26,27,28,1,2)

Any idea?

Thanks,

S.Selvakuamr

• ###### Re: Difference between two Dates

try

Interval() function

example--

Interval(EndDate - StartDate)

• ###### Re: Difference between two Dates

Updated code

=Num(date#('2-Mar-2013','D-MMM-YYYY'))+1 - num(date#('24-Feb-2013','D-MMM-YYYY'))

=Num(date#('End','D-MMM-YYYY'))+1 - num(date#('Start','D-MMM-YYYY'))

=date#('End','D-MMM-YYYY')+1 - date#('Start','D-MMM-YYYY')

iNTERVAL(date#('2-Mar-2013','D-MMM-YYYY') - date#('24-Feb-2013','D-MMM-YYYY'),'DD')

• ###### Re: Difference between two Dates

Make sure that you have interpreted the fields correctly using Date#() or TimeStamp#() - Not Date() and TimeStamp(). If you have done so, you can just subtract one date from another and the result will be number of days between the two.

Date#(END, 'DD-MMM-YYYY') - Date#(START, 'DD-MMM-YYYY') as Duration

HIC

• ###### Re: Difference between two Dates

Thanks HIC but how to include Start and End date...

Let me put this in way, count of days between  Start and end date (Including start and end date)

Selva

• ###### Re: Difference between two Dates

Simply add 1 to the result. Or use DayStart for the start date and DayEnd for the end date and round the result: round(dayend(end)-daystart(start))

• ###### Re: Difference between two Dates

Thanks Gysbert.. "Dayend" does the trick..

Selva