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: 
SterreKapteijns
Partner - Contributor III
Partner - Contributor III

now() does not generate current timestamp in load script

Hi, 

I am trying to generate a UNIX timestamp with the now() function that needs to be used in a API call. I need to generate the UNIX timestamp at the moment of calling the API endpoint.

Therefore I use: let vtimestamp = Floor(now()-MakeDate(1970,1,1))*86400;

However, it is not working as expected. At this moment, it returns for example '1718409600', while the current timestamp is 1718458763. Even when I refresh the page and run the script again, it still returns an old value. 

Is there some reason why I do not get the current timestamp? 

Thanks in advance. 

Kind regards, Sterre

Labels (2)
1 Solution

Accepted Solutions
Or
MVP
MVP


@SterreKapteijns wrote:

Of course I run the script, but then the function will still not return the current timestamp. 

Furthermore, I need the timestamp, not the date and today(1) will return the date.


Even more confused now. If you need the timestamp, why are you floor()ing?

Or_0-1718625192298.png

 

Did you perchance intend to floor() outside of the multiplication by seconds?

Floor((now()-MakeDate(1970,1,1))*86400)

View solution in original post

10 Replies
rubenmarin

Hi, the default returns the last finished data load, try with Now(1): https://help.qlik.com/en-US/qlikview/May2024/Subsystems/Client/Content/QV_QlikView/Scripting/DateAnd...

SterreKapteijns
Partner - Contributor III
Partner - Contributor III
Author

Hi, 

I have tried using Now(1), but I still get an 'old' timestamp. 

Kind regards, 

Sterre

Or
MVP
MVP

I am a tad confused. Why would the timestamp created during the reload script change when you open or refresh the app? Opening or refreshing the app does not run the reload script...

If that's what you're after, you can use the variable editor to create an on-the-fly variable rather than creating it in your script.

 

rubenmarin

As the linked help page states:

now( 1)

  • When used in a chart expression, this returns the time of the function call.
  • When used in a load script, this returns the time of the function call in the current data load.
SterreKapteijns
Partner - Contributor III
Partner - Contributor III
Author

I need the variable in the API call, therefore creating the on-the-fly variable would no be possible right? 

SterreKapteijns
Partner - Contributor III
Partner - Contributor III
Author

Yeah I have read the documentation, however it does not work as described. The function is called in the load script, however it does not return the time the function is called during the data load.

Or
MVP
MVP

If you're making the API call from script, then you would indeed want to use a script variable, but - that variable doesn't change when you open the app, only when the script is run.

I'd also suggest using today(1) rather than Now(1), since you seem to be floor()ing away the time aspect anyway, but that shouldn't impact the result, just cleaner to read.

SterreKapteijns
Partner - Contributor III
Partner - Contributor III
Author

Of course I run the script, but then the function will still not return the current timestamp. 

Furthermore, I need the timestamp, not the date and today(1) will return the date.

Or
MVP
MVP


@SterreKapteijns wrote:

Of course I run the script, but then the function will still not return the current timestamp. 

Furthermore, I need the timestamp, not the date and today(1) will return the date.


Even more confused now. If you need the timestamp, why are you floor()ing?

Or_0-1718625192298.png

 

Did you perchance intend to floor() outside of the multiplication by seconds?

Floor((now()-MakeDate(1970,1,1))*86400)