Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
grajmca_sgp123
Creator
Creator

How to compare two date values

Hi All,

I am trying to compare two date values ,one date is coming from Created Date field and another date is Variable date which we hard coded. Both field date and Variable date also in same format

Let vCreationDate = date('2/1/2015')


this is the condition I am trying to compare but not able to get the correct result.

if([Created Date] > $(vCreationDate),'0',BW)

Thanks

1 Solution

Accepted Solutions
marcus_sommer

You need to make sure that both variable and field will be recognized as date:

Let vCreationDate = date(date#('2/1/2015', 'M/D/YYYY'), 'M/D/YYYY');


and then: if([Created Date] > '$(vCreationDate)','0',BW)

but better is always to compare pure numeric values:

Let vCreationDate = num(date#('2/1/2015', 'M/D/YYYY'));


and then: if(num([Created Date])> $(vCreationDate),'0',BW)

see also: How to use - Master-Calendar and Date-Values

- Marcus

View solution in original post

4 Replies
jagan
Luminary Alumni
Luminary Alumni

Hi,

Where you are comparing this?  In script or in Set Analysis?

Regards,

Jagan.

grajmca_sgp123
Creator
Creator
Author

in script level jagan mohan

marcus_sommer

You need to make sure that both variable and field will be recognized as date:

Let vCreationDate = date(date#('2/1/2015', 'M/D/YYYY'), 'M/D/YYYY');


and then: if([Created Date] > '$(vCreationDate)','0',BW)

but better is always to compare pure numeric values:

Let vCreationDate = num(date#('2/1/2015', 'M/D/YYYY'));


and then: if(num([Created Date])> $(vCreationDate),'0',BW)

see also: How to use - Master-Calendar and Date-Values

- Marcus

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

Let vCreationDate = Date(Date#('2/1/2015', 'M/D/YYYY'), 'M/D/YYYY');


Note: change this format accordingly M/D/YYYY or D/M/YYYY


LOAD

*,

If([Created Date] > '$(vCreationDate)','0',BW) AS NewFieldName

FROm Datasource;


Hope this helps you.


Regards,

Jagan.