# Time Of Day Based Dynamic Changes Via With Code?

**URL:** <https://forum.wixstudio.com/t/time-of-day-based-dynamic-changes-via-with-code/39175>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [June 5, 2018, 5:30pm UTC](https://forum.wixstudio.com/t/time-of-day-based-dynamic-changes-via-with-code/39175 "2018-06-05T17:30:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![omid-symmetra](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/omid-symmetra/32/710_2.png) [@omid-symmetra](https://forum.wixstudio.com/u/omid-symmetra)\
**Post date:** [June 5, 2018, 5:30pm UTC](https://forum.wixstudio.com/t/time-of-day-based-dynamic-changes-via-with-code/39175/1 "2018-06-05T17:30:19Z")

</div>

Hi,

I want to use code that will allow me to change a background of a strip or a page or other content on the page based on different time of days as READ FROM visitsor computer/device settings. I previoiusly employed redirects to get this done when I needed such things, with multiple versions of the same page for different times of day.

Is this going to be possible directly using Wix Code any time soon? If so, a little guidance on how it might be done would be appreciated.

Basically, I want my page to be able to show GOOD MORNING message via a dynamicly/code depenedent text element if you will and a background picture that goes well with morning time… and say good afternoon and show an afternoon related image on page backgroujnd for afternoon, and so on for evening. I know my time brackets and just need to know if I can accomplish this via a single dynamic page / url AS opposed to having to workaround and do those kinds of things.

Thanks!  
Omid

---

<div class="post-metadata">

**Author:** ![andreas-kviby](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/andreas-kviby/32/790_2.png) [@andreas-kviby](https://forum.wixstudio.com/u/andreas-kviby)\
**Post date:** [June 6, 2018, 2:21pm UTC](https://forum.wixstudio.com/t/time-of-day-based-dynamic-changes-via-with-code/39175/2 "2018-06-06T14:21:28Z")

</div>

Can you change the image through code?

---

<div class="post-metadata">

**Author:** ![mqumseya](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mqumseya/32/3999_2.png) [@mqumseya](https://forum.wixstudio.com/u/mqumseya)\
**Post date:** [June 7, 2018, 7:20am UTC](https://forum.wixstudio.com/t/time-of-day-based-dynamic-changes-via-with-code/39175/3 "2018-06-07T07:20:16Z")

</div>

Hello Omid,

Yes this is possible using Wix code, below I have created a boilerplate for you to use.  
You can find more information on **date.getHours()** - [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours) , and **background.src** - [here](https://www.wix.com/code/reference/$w.Background.html) .

```javascript
const date = new Date(); //Get the current Date
const hour = date.getHours(); //We get the hour here (0-23)

if(hour <= 12){ //Customize the hours according to your preference 
  $w('#greetingText').text = 'Good Morning';
  $w("#greetingImage").background.src = "http://placehold.it/250x250"; //Your good-morning Image
}else {
  $w('#greetingText').text = 'Good Afternoon';
  $w("#greetingImage").background.src = "http://placehold.it/250x250"; //Your good-afternoon Image
}                          

```

Hope this helps,  
Majd

---

<div class="post-metadata">

**Author:** ![omid-symmetra](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/omid-symmetra/32/710_2.png) [@omid-symmetra](https://forum.wixstudio.com/u/omid-symmetra)\
**Post date:** [June 22, 2018, 2:04pm UTC](https://forum.wixstudio.com/t/time-of-day-based-dynamic-changes-via-with-code/39175/4 "2018-06-22T14:04:33Z")

</div>

Majd, Vielen Dank mein Freund!
