Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Find hours between dates

Hello,

I'm having trouble trying to find the amount of hours,positive or negative, between my date field and today's date.  I've looked on other discussions and can't seem to find the solution.

Here's the formula in my script.  It is returning null values.

Interval(timestamp(now(),'M/D/YYYY hh:mm')-timestamp(Date1,'M/D/YYYY hh:mm')) as Interval,

Is there another function that I should be using?

Thank you in advance.

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Have you checked that Date1 shows a numeric representation (can be formatted as number)?

Then this should work

Interval( now()-timestamp#(Date1,'M/D/YYYY hh:mm') ) as Interval,


or if your input value shows seconds as well:

Interval( now()-timestamp#(Date1,'M/D/YYYY hh:mm:ss') ) as Interval,

View solution in original post

5 Replies
swuehl
MVP
MVP

You don't need to format your timestamps using Timestamp(), but that should not be the issue here.

Ensure that Date1 is read in correctly, interpreted as timestamp by QlikView:

Why don’t my dates work?

Get the Dates Right

QlikView Date fields

hector_munoz
Specialist
Specialist

Hi David,

Once I used somenthing like this and worked:

=(Timestamp(Now(), 'DD/MM/YYYY hh:mm:ss') - Timestamp([Creation Date], 'DD/MM/YYYY hh:mm:ss')) * 24

Regards,
H

Anonymous
Not applicable
Author

Hello Stefan,

Thank you for your reply.

I have the date being formatted in the script to M/D/YYYY hh:mm and it's being read as such when I pull the field into a listbox


Timestamp#(Date1,'M/D/YYYY hh:mm:ss') as Date1

swuehl
MVP
MVP

Have you checked that Date1 shows a numeric representation (can be formatted as number)?

Then this should work

Interval( now()-timestamp#(Date1,'M/D/YYYY hh:mm') ) as Interval,


or if your input value shows seconds as well:

Interval( now()-timestamp#(Date1,'M/D/YYYY hh:mm:ss') ) as Interval,

Anonymous
Not applicable
Author

This works, thank you so much!