# Manipulating sunset for duration

**URL:** <https://community.smartthings.com/t/manipulating-sunset-for-duration/125181>\
**Category:** webCoRE\
**Created:** [April 25, 2018, 2:54pm UTC](https://community.smartthings.com/t/manipulating-sunset-for-duration/125181 "2018-04-25T14:54:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mismarthome](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@mismarthome](https://community.smartthings.com/u/mismarthome)\
**Post date:** [April 25, 2018, 2:54pm UTC](https://community.smartthings.com/t/manipulating-sunset-for-duration/125181/1 "2018-04-25T14:54:47Z")

</div>

I am stuck. I am trying to get my lights to turn on at a certain time (sunset - 30) and then fade from 100% to 20% and hit 20% at 9pm. I’ve tried different expressions for the duration, but keep coming up with high numbers. For instance:

{datetime(‘9PM’)} - {$sunset}

Gives me a large negative number (-32275537). Can someone give me a push in the right direction? Thanks!

---

<div class="post-metadata">

**Author:** ![Ryan780](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/ryan780/32/103505_2.png) [@Ryan780](https://community.smartthings.com/u/Ryan780)\
**Post date:** [April 25, 2018, 3:10pm UTC](https://community.smartthings.com/t/manipulating-sunset-for-duration/125181/2 "2018-04-25T15:10:38Z")

</div>

What if sunset is after 9pm? Or what if sunset is 4 pm. You want the lights to fade out for 5 hours? The number you are getting is in epoch time. And first of all 9PM is not a time that unix will understand. I assume you’re using a Webcore expression? (Should really be on the webcore forum but we’ll let it slide). If so, you want to put it in the correct format. I would do something like this.

(addHours($nextmidnight,-3)-$sunset) / 60,000 That should give you the number of minutes you’re looking for.

---

<div class="post-metadata">

**Author:** ![rontalley](https://avatars.discourse-cdn.com/v4/letter/r/e47774/32.png) [@rontalley](https://community.smartthings.com/u/rontalley)\
**Post date:** [April 25, 2018, 3:19pm UTC](https://community.smartthings.com/t/manipulating-sunset-for-duration/125181/3 "2018-04-25T15:19:35Z")

</div>

Don’t know what you are using but I would do it like this in webCoRE:

 ![Time%20Expression](https://global.discourse-cdn.com/smartthings/original/3X/b/9/b910f587dcc65145b1fa108e680e3db098e14434.png)

I tested it and it works:

 ![Fade%20Proof](https://global.discourse-cdn.com/smartthings/original/3X/2/c/2c40a3b851a50dca5b5aee8e98eb564f63e9d2ca.png)
