Web Hosting Talk







View Full Version : Getting the date and next 3 days in drop down


blue72
05-30-2006, 10:04 PM
I am having a lot of trouble trying to make this...I need a drop down box that displays todays date as well as the next 3 days in this format:

Tuesday 05/30/06
with other selections being:
Wednesday 05/31/06
Thursday 06/01/06
Friday 06/02/06

But, it has to update itself depending on what day it is...so that works for today, but tomorrow it has to be Wed - Sat.

I really appreciate any help! thanks in advance

brendandonhu
05-30-2006, 10:15 PM
What language are you trying to do this in?

blue72
05-30-2006, 10:41 PM
html/javascript

mr e
05-30-2006, 11:10 PM
I would do something like

var today = new Date()
var tomorrow = new Date()
var dayafter = new Date()

tomorrow.setDate(today.getDate() + 1)
dayafter.setDate(today.getDate() + 2)

then you can use normal Date functions to get the day/month/year such as today.getHours() or tomorrow.getMonth()

hope that helps :)

brendandonhu
05-30-2006, 11:20 PM
You can do this with the Date() object in javascript (using the getDay, getDate, getMonth, and getFullYear methods) but you might run into problems if your user has javascript disabled or has their clock set wrong. Does your webhost support a serverside language like PHP? It would be better to use that.

blue72
05-31-2006, 12:57 AM
I used
tomorrow.setDate(today.getDate() + 1)
dayafter.setDate(today.getDate() + 2)
and it worked good, except I couldn't figure how to format it properly.

This is what I have to get me to Wednesday 5/31/06. I'm still not sure how to get the other dates to show up properly in this format. I used a for loop, and was able to get the day name to change right, but then the month would change and the days were going 32, 33 and so on. It's part of an admin area, so I'll be the only one to use it, and javascript makes it easier to put into the page than php.

<script type="text/javascript">
var mydate= new Date()
var theyear=mydate.getFullYear()
var themonth=mydate.getMonth()+1
var thetoday=mydate.getDate()
var nday=mydate.getDay()

if (nday==0)
nday="Sunday";
if (nday==1)
nday="Monday";
if (nday==2)
nday="Tuesday";
if (nday==3)
nday="Wednesday";
if (nday==4)
nday="Thursday";
if (nday==5)
nday="Friday";
if (nday==6)
nday="Saturday";

theyear-=2000;

document.write(nday+" "+themonth+"/"+thetoday+"/0"+theyear)

</script>

blue72
05-31-2006, 02:51 PM
Well I got some sleep, and what you posted worked. Thanks for the help.

Ended up with this, posting it so I don't lose it!

<html>
<head>
<script type="text/javascript">
Date.NDAY = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
Date.prototype.toDateString = function () {return [Date.NDAY [this.getDay()]," ", this.getMonth()+1,"/", this.getDate(),"/", "0",this.getFullYear()-2000].join ('')}


if (document.getElementById) onload = function () {
dateToday = new Date()
dateToday.setDate (dateToday.getDate())
document.getElementById ('date-today').firstChild.data = dateToday.toDateString()
dateTomorrow = new Date()
dateTomorrow.setDate (dateTomorrow.getDate()+1)
document.getElementById ('date-tomorrow').firstChild.data = dateTomorrow.toDateString()
dateDayAfter = new Date()
dateDayAfter.setDate (dateDayAfter.getDate()+2)
document.getElementById ('date-dayafter').firstChild.data = dateDayAfter.toDateString()
dateDayAfterNext = new Date()
dateDayAfterNext.setDate (dateDayAfterNext.getDate()+3)
document.getElementById ('date-dayafternext').firstChild.data = dateDayAfterNext.toDateString()
}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<span id="date-today">Today</span><br />
<span id="date-tomorrow">Tomorrow</span><br />
<span id="date-dayafter">Day After Tomorrow</span><br />
<span id="date-dayafternext">Day After Next Tomorrow</span><br />
</body>
</html>