Display a date string

Posted on
Thu Feb 16, 2017 7:56 am
Professor Falken offline
User avatar
Posts: 126
Joined: Mar 29, 2015

Display a date string

I feel like this should be an easy task, but even after several hours last night I couldn't figure out a reasonable solution.

I would like to have the date display on my control pages in the following format

Thursday
February 16, 2017


But I can't figure out how to generate those two separate line items as variables (or device states).

AppleScript has a "date string" function, but that returns: "Thursday, February 16, 2017" all in one item (so not good for my two line control page display).

I can get the numerical day and year via AppleScripts (day of current date and year of current date), but if I try to call either the weekday or month of current date, I get a 3 letter abbreviation (mon, tue, wed, jan, feb, mar) instead of the full weekday or month-- not really the effect I'm looking for on the control page.

As a work-around for the weekday, and because it is alone on a line, I just had Indigo set a variable to the current weekday at midnight every day (7 scheduled actions). In theory I could do this on the first of every month for the month, then use AppleScript to get the day and year, and mash it all together in one line on the control page. But then the spacing isn't going to work, because different months have different numbers of letters.

Surely I am missing an easy solution to this issue, right?

Posted on
Thu Feb 16, 2017 10:42 am
jay (support) offline
Site Admin
User avatar
Posts: 13263
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Display a date string

In a python script (execute it at midnight every day):

Code: Select all
from datetime import date
indigo.variable.updateValue(123, date.today().strftime("%A"))  # substitute the ID of the variable that will hold the weekday
indigo.variable.updateValue(456, date.today().strftime("%B %d, %Y"))  # substitute the ID of the variable that will hold the date string


The result is that variable 123 will have: Thursday and variable 456 will have: February 16, 2017 (if run on the day I posted this reply).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Feb 16, 2017 10:46 am
johnpolasek offline
Posts: 737
Joined: Aug 05, 2011
Location: Aggieland, Texas

Re: Display a date string

Could you do the same thing from a schedule with two "Insert Timestamp into Variable" actions and set the same "%A" and "%B %d, %Y" custom formats into the action items without using a script?

Posted on
Thu Feb 16, 2017 11:02 am
Professor Falken offline
User avatar
Posts: 126
Joined: Mar 29, 2015

Re: Display a date string

Thanks for the quick reply Jay. I'll give that a try this evening. I guess if I'm going to be using the more advanced feature of Indigo, I'm going to have to branch out from AppleScript and learn some Python.

I am continuously amazed at how powerful Indigo is, thanks for creating and supporting such a great product.

Posted on
Thu Feb 16, 2017 12:09 pm
jay (support) offline
Site Admin
User avatar
Posts: 13263
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Display a date string

johnpolasek wrote:
Could you do the same thing from a schedule with two "Insert Timestamp into Variable" actions and set the same "%A" and "%B %d, %Y" custom formats into the action items without using a script?


LOL. Totally.

I completely forgot about that action - it's a much better solution.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Feb 16, 2017 7:13 pm
Professor Falken offline
User avatar
Posts: 126
Joined: Mar 29, 2015

Re: Display a date string

Worked perfectly. Thanks for both solutions.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest