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

compare datetime in scriptside

Hi All,

I want to compare  datetime field in script side fro Ex:

StDtTm is 01/10/2014 07:20:33 and EndDtTm is 12/26/2013 11:10:18

In above case I want to compare if EndDtTm > StDtTm then i want to set flag as 'Y' else 'N' as flag so how to compare it in script side.

1 Solution

Accepted Solutions
tresesco
MVP
MVP

If these datetimes are timestamps, the simple comparison should work like:

Load

     If( EndDtTm > StDtTm, 'Y', 'N') as Flag

If they are text, try like:

If( Timestamp#(EndDtTm, 'MM/DD/YYYY hh:mm:ss') > Timestamp#(StDtTm, 'MM/DD/YYYY hh:mm:ss'), 'Y', 'N') as Flag

View solution in original post

5 Replies
tresesco
MVP
MVP

If these datetimes are timestamps, the simple comparison should work like:

Load

     If( EndDtTm > StDtTm, 'Y', 'N') as Flag

If they are text, try like:

If( Timestamp#(EndDtTm, 'MM/DD/YYYY hh:mm:ss') > Timestamp#(StDtTm, 'MM/DD/YYYY hh:mm:ss'), 'Y', 'N') as Flag

ashfaq_haseeb
Champion III
Champion III

Hi,

write the below code in your script.

if (EndDtTm>StDtTm,'Y','N') as Flag



Regards

ASHFAQ

Not applicable
Author

Hi,

Use Something Like this

if(Timestamp#(EndTime,'MM/DD/YYYY hh:mm:ss')  >timestamp#(StartTime,'MM/DD/YYYY hh:mm:ss') ,'Y','N')

Regards,

Vivek

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

LOAD

*,

If(EndDtTm > StDtTm, 'Y', 'N') AS Flag

FROM DataSource;


If above not working then try like this

LOAD

*,

If(Timestamp#(EndDtTm ,'MM/DD/YYYY hh:mm:ss')  >Timestamp#(StDtTm,'MM/DD/YYYY hh:mm:ss') ,'Y','N')

FROM DataSource;


Hope this helps you.


Regards,

Jagan.


PrashantSangle

Hi,

It is better if convert it number while compare

Try like,

if(Num(Timestamp(Timestamp#(EndTime,'MM/DD/YYYY hh:mm:ss')))  >Num(Timestamp(timestamp#(StartTime,'MM/DD/YYYY hh:mm:ss'))) ,'Y','N') as Flag

Regards

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂