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: 
Not applicable

Changing date for a certain time span

Hey guys,

Basically I am looking at a time stamp and saying if this field is after 2pm or before 8 am the make the date associated with it one day earlier.

below is what I've tried

if(LIKP.Time_ERZET = ('14:00:00' , '00:07:59') , LIKP.CreatedOn_ERDAT = date(LIKP.CreatedOn_ERDAT -1)),

*the time field is formated in military time*







I've tried a few other variations as well

like using NOT etc. But I feel like my problem is this part ('14:00:00' , '00:07:59'). I make any date field associated with these time one day earlier.

Can anyone help?

Thanks, Alex

2 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

If your timestamp is formatted as a string, it's very difficult operating with it. I'd recommend casting it into a proper timestamp, using one of the "Interpretation functions" (search Help for this name) for example:

myTime = time#(Timestring, 'hh:mm:ss')

Once you convert your strings into proper time or timestamp fields, you can operate with them as with numbers:

1 day = 1

1 hour = 1/24

8:00 AM corresponds to 8/24 = 1/3

2:00 PM = 14:00, corresponds to 14/24 = 7/12

etc...

Not applicable
Author

Hello Oleg,

I tried:

time#(timestring, 'hh:mm:ss') However, it did not convert the string to a number. It still returns times in the same format as before. Not sure if that's what you meant Tongue Tied