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: 
rcandeo
Creator III
Creator III

How can I get actual date in a macro?

I have a variable field that I need to fill with actual date in a macro function. Someone can help with the correct code?

1 Solution

Accepted Solutions
johnw
Champion III
Champion III

ActiveDocument.GetVariable("Today").setContent ActiveDocument.Evaluate("today()"),false

View solution in original post

7 Replies
Not applicable

Something like this:

ActiveDocument.Variables("TheDate").SetContent now(), true

johnw
Champion III
Champion III

ActiveDocument.GetVariable("Today").setContent ActiveDocument.Evaluate("today()"),false

johnw
Champion III
Champion III

And our two different responses bring up some questions in my mind.

1) Is there any difference between Variables and GetVariable? They take the same parameter and return the same value. Is one of them deprecated and the other preferred? Are they just two aliases for the same actual code being executed?

2) The API documentation says that the parameter you set to true and I set to false should be "true if value to be added to MRU list". What the heck is an MRU list? There's no mention of it in the reference manual.

3) Now() vs. ActiveDocument.Evaluate("today()"). This one I'm pretty sure I understand. the now() function is using a Visual Basic function to return the current timestamp. the ActiveDocument.Evaluate("today()") is using a QlikView function to return the current date. I tend to use Evaluate and QlikView functions for a sort of consistency, but either should do the trick.

Not applicable

MRU = most recently used

Not applicable

Here are my thoughts:

1. No idea. I started using Variables, because a coworker had set up some macros and that is what she used. The sample code is pretty much the same. Hopefully, there would be some notification if one of them was becoming obsolete. I'd much rather change to one or the other now, rather than in a year when I have more files to go back and change. GetField and Field seem to work the same.

2. This is similar to 1 as I've seen true used, so I have been using it without really knowing what it did (bad, I know). MRU could stand for Most Recently Used, but I don't see a Most Recently Used section for variables. Maybe a future feature?

3. There was a thread that came up where someone was having an issue with getting the current time, because they were running the documents off the server (the server and users were in different timezones). In this case, I believe your formula would give the server time, while mine should give the user's computer time (I got my formula from that thread). I currently don't run any apps from a server, but I could definitely see a need for both in a multi-time zone environment.

rcandeo
Creator III
Creator III
Author

The difference between the two options that you gave to me, is that the first one brings back actual date with hour, and the second one gives back only the actual date.

Not applicable

Yes, the function for date only in VB is date(), instead of now().