Format DateTime item state

I would like to format the state of a DateTime item. This error date should be sent via email.
Can I change the format of the DateTime item to: “18.08.2017 20:20”?


DateTime ErrorDate "Error date [%1$td.%1$tm %1$tH:%1$tM]" {channel="binding:name:name:error#date"}


sendMail("", "Error", "\nError Date: " + ErrorDate.state)

Received email:

Error Date: 2017-08-18T20:20:48.000+0200
1 Like

I’m not sure if there is an easier way, but what I do in my rules could look similar to this for your use case


  var DateTime error = parse(""+ErrorDate.state)
  sendMail("", "Error", "\nError Date: " + error.toString("dd.MM.yyyy HH:mm"))

Something like this should work, in theory, if you replace the format markers appropriately:

var String tmp = ErrorDate.state.format("%1$td.%1$tm %1$tH:%1$tM")

Found in this thread.


Thanks for the tips.
So I solved it like @namraccr suggested it:

sendMail("", "\nError Date: " + ErrorDate.state.format("%1$td.%1$tm.%1$ty %1$tH:%1$tM"))
1 Like