Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   Javascript Date Script (http://www.greenguysboard.com/board/showthread.php?t=42871)

Doug E 2007-09-21 09:10 AM

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:


Ohh yea, and its creation is credited to http://www.wsabstract.com/

Llam4 2007-09-21 09:52 PM

now.getunit 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 +".")

AndySvk 2007-09-28 01:30 PM

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:


I think you get the point ...

Doug E 2007-10-08 11:56 PM

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 :)


All times are GMT -4. The time now is 03:23 PM.

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