postUpdate of DateTimeType

Can anyone please tell me how to do a postUpdate of a DateTime to a datetime or string item?

The only way I can seem to get anything of use out of it is by using a string type and the code below, tho I’d like to extract just the hours and minutes from the whole date.


rule "Sunset trigger times update"
when 
    Time cron "0 0/1 * 1/1 * ? *"
then
    val SunsetLightsTrigger = new DateTime((SunsetTime.state as DateTimeType).calendar.timeInMillis)
    SunsetLightsTrigger = SunsetLightsTrigger.minusMinutes(20)
    postUpdate(SunsetLightsTime," " + SunsetLightsTrigger)
end


Hi Neil,

maybe this example helps:

rule BerechneDatumZeitUI
when
    Time cron "0 0/1 * * * ?" // Jede Minute
                              // http://www.cronmaker.com/
then	
        // https://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
	// http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html
	
	val Datum       = now.toDateTime.toString("dd. MMMM yyyy '(KW' w')'")
	val Zeit        = now.toDateTime.toString("HH:mm") 
	val ZeitKompakt = now.toDateTime.toString("HH:mm, E dd.MM.y '(KW' w')'")
	
	AktuelleZeitString.postUpdate(Zeit)
	AktuelleDatumString.postUpdate(Datum)
	AktuelleZeitKompakt.postUpdate(ZeitKompakt)
end
```

with kind regards,
Patrik

Patrik, you’re a star.

That worked, thank you. :slight_smile: