Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

How do I set a variable to current time?

If you have a question or need help, this is the place to be.
Post Reply
wysocki
Experienced User
Posts: 65
Joined: Mon Nov 23, 2015 9:23 pm
Location: Los Angeles area

How do I set a variable to current time?

Post by wysocki »

I want to capture the current local time (as "hh:mm:ss") into a temporary variable in a macro. I've tried the action "Set temporary Variable" with a value of {eg.event.time.strftime('%X %x %Z')} but just get an error. If I set the value to {eg.event.time} I DO get a numeric string like 100343.402617 but that's not what I want.

It'd be nice to find a list of possible values for xxx in {eg.event.xxx}
kkl
Experienced User
Posts: 317
Joined: Wed May 04, 2011 9:32 pm

Re: How do I set a variable to current time?

Post by kkl »

I usually use Python commands for getting the time. Here's an example you can try:

Code: Select all

import time; mytime = time.strftime("%H:%M:%S"); print mytime
It'd be nice to find a list of possible values for xxx in {eg.event.xxx}
This info can be found here. However, many more values are available and you can find these in a little known section of EG. In the Help menu, select Python Shell. At the lower part of the window, look in the Namespace tab. Under eg.globals, expand eg then event and you'll find a large number of built-in eg.event.* variables.
wysocki
Experienced User
Posts: 65
Joined: Mon Nov 23, 2015 9:23 pm
Location: Los Angeles area

Re: How do I set a variable to current time?

Post by wysocki »

Thanks! With your help, I created a temporary variable named "nowTime" in a Python Script like this:

Code: Select all

import time
eg.plugins.Webserver.SetValue(u'mailOTime', time.strftime("%H:%M:%S"), False, False)
Pretty good for a beginner, eh?!
But I wonder, couldn't it be done with the Set Temporary Variable action? I don't know enough about Python and how to work with it in EG. I was thinking I could use curly braces or something in the action value to use the calculation as opposed to writing a script which called the webserver function, but I couldn't get that to work.

Also thanks for the tip on the Python Shell!
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: How do I set a variable to current time?

Post by Pako »

You can also do it this way:
Time2Val.png
Time2Val.png (7.52 KiB) Viewed 2541 times
Pako
You know flattr ? You can Image
Post Reply