Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
clarenceclay
Contributor II
Contributor II

Comparing two dates

Hi There,

I have two dates as follow;

1.  num(Date(monthend(today(),-1), 'DD/MM/YYYY hh:mm:ss[.fff]')) which gives me 44012.999999988

2. num(Date('30/06/2020 23:59:59', 'DD/MM/YYYY hh:mm:ss[.fff]')) which gives me 44012.999988426

Basically both code returns the same date ie '31/06/2020 23:59:59' but the number representative is not the same. How could one construct the date so that it will return the same num values? 

Many thanks in advance. 

1 Solution

Accepted Solutions
brunobertels
Master
Master

Hi 

Note that functions like monthend, yearend etc return the last miliseconde of the imput value 

 

So if you want exactely the same value use dayend() function like this :

num(dayend(Date('30/06/2020 23:59:59', 'DD/MM/YYYY hh:mm:ss[.fff]'))) 

this will give you the same result as 

num(Date(monthend(today(),-1), 'DD/MM/YYYY hh:mm:ss[.fff]'))

 

hop it helps

 

View solution in original post

4 Replies
Taoufiq_Zarra

Floor It!

you can use Floor(Date(monthend(today(),-1), 'DD/MM/YYYY hh:mm:ss[.fff]')) and Floor(Date('30/06/2020 23:59:59', 'DD/MM/YYYY hh:mm:ss[.fff]')) to compare the date

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
brunobertels
Master
Master

Hi 

Note that functions like monthend, yearend etc return the last miliseconde of the imput value 

 

So if you want exactely the same value use dayend() function like this :

num(dayend(Date('30/06/2020 23:59:59', 'DD/MM/YYYY hh:mm:ss[.fff]'))) 

this will give you the same result as 

num(Date(monthend(today(),-1), 'DD/MM/YYYY hh:mm:ss[.fff]'))

 

hop it helps

 

clarenceclay
Contributor II
Contributor II
Author

Hi Sir,

I purposely do not want to use FLOOR because i want to preserve the timestamp info from the dates. 

Thank you

clarenceclay
Contributor II
Contributor II
Author

Hi Sir,

Thank you for the explanation. It helps me figure out what exactly went wrong with my dates formatting. In my requirements, i need to remove the milisecond from the date. I came out with the below and now I'm getting the same num value for both dates. Many thanks again sir!.

Timestamp#(Timestamp(monthend(today(),-1),'DD/MM/YYYY hh:mm:ss'),'DD/MM/YYYY hh:mm:ss')