# Date object with if/else?

**URL:** <https://forum.kirupa.com/t/date-object-with-if-else/45517>\
**Category:** Uncategorized\
**Created:** [March 15, 2004, 2:49pm UTC](https://forum.kirupa.com/t/date-object-with-if-else/45517 "2004-03-15T14:49:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![max56](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/max56/32/465_2.png) [@max56](https://forum.kirupa.com/u/max56)\
**Post date:** [March 15, 2004, 2:49pm UTC](https://forum.kirupa.com/t/date-object-with-if-else/45517/1 "2004-03-15T14:49:53Z")

</div>

i’m using the date object to pull up different movies at different times of day. but can’t figure out the syntax for the if/else statement to allow for time frames.  
this is what i want in english.  
play movie A between 8am-1pm then play movie B between 1pm-5pm. then  
play movie C between 5pm-8pm then  
play movie D between 8pm-midnight etc  
I actually want 5 different time frames for 5 different movies.  
here’s my actionscript attempt.

on (release) {  
now = new Date();  
now.getHours()  
if (now \<= 13) {  
getURL(“hmorning.html”, “mainthing”);  
} else if (now \>= 13 ) {  
getURL(“hafternoon.html”, “mainthing”);  
} else if (now \>= 17 ) {  
getURL(“heven.html”, “mainthing”);  
}  
}

this only works for two different time frames. greater than/less than.  
any ideas… much appreciated.  
max

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 15, 2004, 3:46pm UTC](https://forum.kirupa.com/t/date-object-with-if-else/45517/2 "2004-03-15T15:46:45Z")

</div>

You need to check if it is between values, not just greater than:

```auto

on (release) {
now = new Date();
now.getHours()
if (8<= now <= 13) {
getURL("hmorning.html", "mainthing");
} else if (13< now <=17 ) {
getURL("hafternoon.html", "mainthing");
} else if (17< now <=23 ) {
getURL("heven.html", "mainthing");
}
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 15, 2004, 4:36pm UTC](https://forum.kirupa.com/t/date-object-with-if-else/45517/3 "2004-03-15T16:36:43Z")

</div>

```auto
on (release) {
	now = new Date().getHours();
	if (now>=8 && now<13) {
		getURL("movieA", "mainthing");
	} else if (now>=13 && now<17) {
		getURL("movieB", "mainthing");
	} else if (now>=17 && now<20) {
		getURL("movieC", "mainthing");
	} else if (now>=20 && now != 0) {
		getURL("movieD", "mainthing");
	} else if (now == 0 || now<8) {
		getURL("movieE", "mainthing");
	}
}

```
