How to assign /system clock get date to a variable in a script?

Hi guys,

How to assign /system clock get date to a variable in a script?

:local date [/system clock get date]
:put $date

$date is always empty :question:

Thanks for helping!

Try this if you are running it the terminal:

:local date [/system clock get date]; put $date;

or

:global date [/system clock get date];
:put $date;

In the terminal, as soon as you execute the first line and are returned to the prompt the content in the “local” variable is lost and that is why putting it on one line is needed.

When you put it in a script “local” it will work because all what is in the script is seen as one line…I think.

When you want to test in the terminal or exchange variable between scripts then you need to use global. When using exchange then you have define the global variable first in the second script.

Perfect, thanks very much, msatter!

This works

:global date [/system clock get date];
:put $date;

>
\
<br>
> In the terminal, as soon as you execute the first line and are returned to the prompt the content in the "local" variable is lost and that is why putting it on one line is needed.
>
> When you put it in a script "local" it will work because all what is in the script is seen as one line....I think.
\
<br>
> When you want to test in the terminal or exchange variable between scripts then you need to use global. When using exchange then you have define the global variable first in the second script.

Correct, I have tested it.