Get the month name, and current year in SmartApp?

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?

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.

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

Then you would need to use event date.

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)

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: