Page 1 of 1
Need JavaScript help
Posted: 2003-12-10 09:36am
by haas mark
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">
<!--
dayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
monName = new Array ("January","February","March","April","May","June","July","August","September","October","November","December")
now = new Date
// -->
</script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
document.write(dayName[now.getDay()] + ", " + monName[now.getMonth()] + " " + now.getDate() + ".")
// -->
</script>
</body>
</html>
Okay, basic code for a current date. Is there ANY WAY to set this so it advances to TOMORROW'S date instead of TODAY'S?
~ver
Posted: 2003-12-10 09:42am
by Dalton
Try this:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">
<!--
dayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
monName = new Array ("January","February","March","April","May","June","July","August","September","October","November","December")
now = new Date
tom = now.getDate()+1
// -->
</script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
document.write(dayName[now.getDay()+1] + ", " + monName[now.getMonth()] + " " + tom + ".")
// -->
</script>
</body>
</html>
Posted: 2003-12-10 09:47am
by haas mark
Thanks.
~ver
Posted: 2003-12-10 09:49am
by Dalton
verilon wrote:Thanks.
Sure. You might need to hack it a bit more to advance the month on 28, 29, 30 or 31.
Posted: 2003-12-10 09:51am
by haas mark
Dalton wrote:verilon wrote:Thanks.
Sure. You might need to hack it a bit more to advance the month on 28, 29, 30 or 31.
Ok.. since I'm pretty much JS-illiterate for the most part, how might I go about doing this? (My little book here doesn't explain that much into current dates.)
~ver
Posted: 2003-12-10 09:56am
by Dalton
Well, it's pretty much a bit of mix and match. If you, say, take the raw array value from the script for the month and filter that through a new array consisting of a list of end dates, you can take THAT result and make an if-then statement like
Code: Select all
if (now.getDate == EndDatevariable) then month == now.getMonth()+1
Of course, there's a lot more hacking to do if you want to make it leap-year friendly...but that's a pain in the ass.
Posted: 2003-12-10 10:03am
by haas mark
Dalton wrote:Well, it's pretty much a bit of mix and match. If you, say, take the raw array value from the script for the month and filter that through a new array consisting of a list of end dates, you can take THAT result and make an if-then statement like
Code: Select all
if (now.getDate == EndDatevariable) then month == now.getMonth()+1
Of course, there's a lot more hacking to do if you want to make it leap-year friendly...but that's a pain in the ass.
-blinks- Huh? Note: I FAILED my Java class at uni because I didn't understand arrays..
~ver
Posted: 2003-12-10 10:11am
by Dalton
verilon wrote:-blinks- Huh? Note: I FAILED my Java class at uni because I didn't understand arrays..
Alright...let me do some quick hacking. Back in a flash.
Posted: 2003-12-10 10:49am
by Dalton
Gonna require a lot of special commands just to make sure you don't get an "undefined" error...
Posted: 2003-12-10 10:57am
by Dalton
See what this does for you.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">
<!--
dayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
monName = new Array ("January","February","March","April","May","June","July","August","September","October","November","December");
endDate = new Array ("31","28","31","30","31","30","31","31","30","31","30","31");
now = new Date();
tod = now.getDate();
tom = now.getDate()+1;
tom2 = dayName[now.getDay()+1];
mon = monName[now.getMonth()];
mon2 = monName[now.getMonth()+1];
mon3 = monName[now.getMonth()-11];
endDateNow = endDate[now.getMonth()];
if (now.getYear()%4 == 0 && now.getMonth()==1) {endDateNow=29};
if (now.getDate() == endDateNow) {mon=mon2};
if (now.getDate()+1 > endDateNow) {tom=tom-endDateNow};
if (now.getMonth() == 11 && now.getDate()+1 > endDateNow) {mon=mon3};
if (now.getDay()+1 > 6) {tom2 = dayName[now.getDay()-6]};
// -->
</script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
document.write(tom2 + ", " + mon + " " + tom + ".")
// -->
</script>
</body>
</html>
Posted: 2003-12-10 11:27am
by haas mark
Seems to work fine. MANY thanks!
Seems today will be a good day yet..
~ver
Posted: 2003-12-10 11:31am
by Dalton
verilon wrote:Seems to work fine. MANY thanks!
Seems today will be a good day yet..
Glad I could help! Let me know if it chokes on any particular date.