Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2007-09-21, 09:10 AM   #1
Doug E
Kids are great, Appu. You can teach them to hate the things you hate and they practically raise themselves now-a-days, you know, with the internet and all
 
Doug E's Avatar
 
Join Date: Mar 2005
Location: Canadeh
Posts: 197
Javascript Date Script

How would I make this script that displays the current date, into something that shows the date 1 week ago? Also, so I understand the different commands, the dates for 3 days ago, 2 weeks ago, 1 month ago and say 3 years ago, just to mix it up a bit. Or is it even possible with this script?

Quote:
<script language="Javascript">
<!--
/*
Today's date script
Visit java-scripts.net or
http://wsabstract.com for this script
*/

var dayName = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")

var monName = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")

var now = new Date

document.write("Today is " + dayName[now.getDay()] + ", " + monName[now.getMonth()] + " "+now.getDate() +".")

//-->
</script>
Ohh yea, and its creation is credited to http://www.wsabstract.com/
Doug E is offline   Reply With Quote
Old 2007-09-21, 09:52 PM   #2
Llam4
A woman is like beer. They look good, they smell good, and you'd step over your own mother just to get one!
 
Join Date: Sep 2007
Location: Arizona
Posts: 52
Send a message via AIM to Llam4
now.get<b>unit</b> returns a number. 1-31 for day, 1-12 for months. Just use those variable instead of the clunky now.getDate() and add or subtract directly.

For example:

If you want to show one year ahead, 2 months behind and 8 days ahead, you'd change
Code:
document.write("Today is " + dayName[now.getDay()] + ", " + monName[now.getMonth()] + " "+now.getDate() +".")
to
Code:
document.write("Today is " + dayName[now.getDay()+8] + ", " + monName[now.getMonth()-2] + " " + now.getDay()+8 + ", " + now.getYear()+1 +".")
Llam4 is offline   Reply With Quote
Old 2007-09-28, 01:30 PM   #3
AndySvk
Internet! Is that thing still around?
 
Join Date: Sep 2007
Posts: 5
I am not sure if the above answer would work .. I think it does not ..
cause dayName[now.getDay()+8] would look for an item in array with index 8+ and there are just 7 days (indexes 0-6) so it would produce an error ..

you can rather use this simple code

Code:
<script>

// current date
var now = new Date();

// our new date
var newDate = new Date();

// let's move 3 days to past
newDate.setDate(now.getDate()-3);

// now let's add 5 hours
newDate.setHours(now.getHours()+5);

// we can add 2 months as well
newDate.setMonth(now.getMonth()+2);

</script>
I think you get the point ...
AndySvk is offline   Reply With Quote
Old 2007-10-08, 11:56 PM   #4
Doug E
Kids are great, Appu. You can teach them to hate the things you hate and they practically raise themselves now-a-days, you know, with the internet and all
 
Doug E's Avatar
 
Join Date: Mar 2005
Location: Canadeh
Posts: 197
Hi thanks very much for the replies guys. I ask these questions than get busy with something else and forget all about them until I have another question.

Im going to play with the code this week and let you know what works best
Doug E is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:43 AM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc