Get the month name, and current year in SmartApp?


#1

I’m looking to enhance the influxdb posting smartapp, and want to include posting prepopulated fields for Month and Year to the influxdb database. It’s a long story, but to make it short, influxdb doesn’t take month or year as group-by criteria, and short of doing some mental gymnastics, I’ve decided that it would just be easiest to include these fields when pushing the data.

So, anybody know how to get e.g. ‘March’ and ‘2018’ from within a SmartApp?


#2

That depends on what your SmartApp is doing and what date you want to pull. Is there an event already being recorded that you are trying to pull the date for? If so, the event date should already be recorded.


#3

Yeah, I’d like to capture the month and year as strings around this section of the SmartApp code:


#4

Then you would need to use event date.
http://docs.smartthings.com/en/latest/ref-docs/event-ref.html


(Mike) #5

Don’t know if it is the best way but here is something used in a smartapp I wrote. I am getting them as integers but you can take that part out.

def currentDate = new Date()
log.debug "Current Date ${currentDate.format(“yyyy-MM-dd HH:mm:ss”, location.timeZone)}"
def currentMonth = (currentDate.format(“MM”, location.timeZone) as BigInteger)
def currentday = (currentDate.format(“dd”, location.timeZone) as BigInteger)


#6

Thanks, using format(“yyyy”, location.timeZone), format(“MMMM”, location.timeZone), and format(“yyyy/MM”, location.timeZone) to get the fields that I was looking for :smile: