Indigo Variable with datetime

Posted on
Sat Oct 01, 2016 1:04 pm
cramer offline
Posts: 33
Joined: Feb 03, 2015

Indigo Variable with datetime

What is the correct way to store a datetime (or time) within and Indigo variable and reconstitute the variable value back to the original object?

Posted on
Sat Oct 01, 2016 1:36 pm
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Indigo Variable with datetime

Here's an example:

Code: Select all
import datetime as dt

# Put the time into a variable.
obj = indigo.server.getTime()
indigo.variable.updateValue('Foobar', str(obj))
   
# Get the time back out.
obj2 = indigo.variables['Foobar'].value
date_obj = dt.datetime.strptime(obj2, '%Y-%m-%d %H:%M:%S.%f')

# Ways to output the date
indigo.server.log(str(date_obj))
indigo.server.log(str(dt.datetime.strftime(date_obj, '%Y-%m-%d %H:%M:%S')))
indigo.server.log(str(dt.datetime.strftime(date_obj, '%Y-%m-%d %H:%M')))
indigo.server.log(str(dt.datetime.strftime(date_obj, '%m-%d-%Y %H:%M')))

Here's the output:
Code: Select all
   Script                          2016-10-01 14:31:52.479000
   Script                          2016-10-01 14:31:52
   Script                          2016-10-01 14:31
   Script                          10-01-2016 14:31

To see the other ways to work with the data, do a Google search on datetime attributes.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Oct 01, 2016 4:13 pm
cramer offline
Posts: 33
Joined: Feb 03, 2015

Re: Indigo Variable with datetime

Many thanks Dave. I didn't expect an answer that fast.

Posted on
Sat Oct 01, 2016 4:34 pm
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Indigo Variable with datetime

My pleasure. Let us know if you have any questions.


Sent from my iPhone using Tapatalk

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests