Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1536 How do I create a Javascript that if it is before a specific time (for example, 9 am) it will display tomorrow's day but will show the day AFTER tomorrow day if it is after that specific time?

irt.org | Knowledge Base | JavaScript | Date | Q1536 [ previous next ]

Q1536 How do I create a Javascript that if it is before a specific time (for example, 9 am) it will display tomorrow's day but will show the day AFTER tomorrow day if it is after that specific time?

Try:

<script language="JavaScript"><!--
var splitTime = (8*60)+59;
var days = new Array('sun','mon','tue','wed','thu','fri','sat');
var now = new Date();
var dayNum = now.getDay(); // 0 = sun -> 6 = sat
var nowTime = (now.getHours()*60) + now.getMinutes();
if (nowTime < splitTime) dayNum-=1;
else if (nowTime > splitTime) dayNum+=1;
if (dayNum < 0) dayNum = 6;
if (dayNum > 6) dayNum = 0;
document.write(days[dayNum]);
//--></script>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.