/    Sign up×
Community /Pin to ProfileBookmark

Check between to numbers?

Hi,

I am trying to now make a little script that checks the time and then will do something. What I am stuck at now is, what do I do if I want something to happen between a few hours. Example, I want an image to display from the hours of 12 am and 5 am, but at 5:30 it will change to something else.

How do I make a statement that looks between 12 and 5:29, and then be able to declair a new if statment and get it to work at 5:30?

Thank you for your help and teachings.

if ((hours <=12 || hours >= 5) && (minutes <=29) && (dayTime == “AM”) {

}

if ((hours ==5 ) && (minutes >=30) && (dayTime == “AM”) {

}

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorOct 04.2005 — why not simply use the 24 hours methods?

[code=php]
<script type="text/javascript">
onload=function(){
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
if((h==17&&m>=30)||(h>17)){//between 17:30 and 23:59:59
...do something
}
else{//between 00:00 and 17:29:59
..do other thing
}
}
</script>
[/code]
×

Success!

Help @learningJavaS spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...