Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Difference between two dates

Hi,

I having trouble in getting difference between two dates which is timestamp. I want the difference in "Days" and create a chart.

Example:-

Field 1 :- 4/11/2013 12:40:32

Field 2 :- 4/16/2013  12:00:00

The value should be "5 days"

17 Replies
sushil353
Master II
Master II

Try this:

date((date(Field1,'MM/DD/YYY')-date(Field2,'MM/DD/YYYY')),'DD')

HTH

Sushil

Not applicable
Author

HI ,

      Try the below code

fabs(Date(Field1,'DD/MM/YYYY')) - fabs(Date(Field2,'DD/MM/YYYY'))

//Yusuf

nirav_bhimani
Partner - Specialist
Partner - Specialist

Hi,

Try this in script

  date(timestamp#(date2,'MM/DD/YYYY hh:mm:ss'),'DD/MM/YYYY') as Dt2,

           date(timestamp#(date1,'MM/DD/YYYY hh:mm:ss'),'DD/MM/YYYY') as Dt1,

           Interval( (date(timestamp#(date2,'MM/DD/YYYY hh:mm:ss'),'DD/MM/YYYY')) -   (date(timestamp#          (date1,'MM/DD/YYYY hh:mm:ss'),'DD/MM/YYYY')), 'd') as DTDiff

Also find the attachment.

Regards,

Nirav Bhimani

sujeetsingh
Master III
Master III

Just use interval function as

Interval(Date1-Date2,'d')

Thanks

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

=Ceil(Interval(Date#('4/16/2013 12:00:00', 'MM/DD/YYYY hh:mm:ss') - Date#('4/11/2013 12:40:32', 'MM/DD/YYYY hh:mm:ss'), 'DD' ))

Hope this helps you.

Regards,

Jagan.

Anonymous
Not applicable
Author

Hi Saaru,

i have some douts on you requrement you want to display days only or time also.

what is the result for your test data.

Regards

SHAIK

Anonymous
Not applicable
Author

Hi Saaru,

i have some douts on you requrement you want to display days only or time also.

what is the result for your test data.

Regards

SHAIK

er_mohit
Master II
Master II

try this

Make sure that your format of date in both field must be same

Date(Date#(Field2,'MM/DD/YYYY hh:mm:ss')-Date#(Field1,'MM/DD/YYYY hh:mm:ss'),'DD') as RestDays

or you can use interval also

Interval(Field2 -Field1,'DD')as Newdays

Not applicable
Author

Thanks Jagan!!

It works when i apply your formula but when I replace with actual field then it is not working like below

=Ceil(Interval(Date#([Field2], 'MM/DD/YYYY hh:mm:ss')-Date#([Field1], 'MM/DD/YYYY hh:mm:ss') , 'DD'))

Am i missing something?