Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 05-17-2004, 12:09 AM   #1
grannytgp
Confirmed User
 
Join Date: Aug 2002
Posts: 269
java-script help - Modifying dates

I'm looking for a way to display not only the current date in "Month Day" format, but also a way to display one day back, two days back, three days back, and so on..

So in the date format, today's date would be "May 17" And yesterday's date would be "May 16", and so on...

From browsing around some java-script sites on google I came across the code to display today's date in this format, but I can't figure out how to manipulate the code to subtract one day, two days, etc...

I have an example page up here: http://www.grannytgp.com/month-day.html

I'm not sure how much code the board will let me post with banned words -- don't want it all looking like "hahahahahaha", so I thought it would be best to throw up the example page

One thing I was also thinking on this code is that it can't "break" when the month changes. So let's say it's now "June 01" The previous day will still need to be displayed at "May 31"

Any help on this would be greatly apprecaited.
__________________
No sig = good sig
grannytgp is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-17-2004, 12:15 AM   #2
bawdy
Confirmed User
 
Join Date: Feb 2002
Posts: 1,424
something like this should work...havent tested it

var MINUTE = 60 * 1000
var HOUR = MINUTE * 60
var DAY = HOUR * 24
var WEEK = DAY * 7


var today = (new Date()).getTime()
var yesterday = new Date(today - (DAY * 1))
var twodaysago = new Date(today - (DAY * 2))
bawdy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-17-2004, 02:08 AM   #3
mazafaka
Confirmed User
 
Join Date: Oct 2002
Posts: 148
<s.c.r.i.p.t.>
function DatePrint(days)
{
var today = new Date();
var theDate = new Date(today.valueOf()-days*86400000);
var day = theDate.getDate();
getmonth = theDate.getMonth();
var monthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
month = monthArray[getmonth];
var ds = '';
if (day < 10)
ds = '0';
document.write(month + " " + ds + day);
}
</s.c.r.i.p.t.>

<s.c.r.i.p.t.>DatePrint(1)</s.c.r.i.p.t.>


-----------------
(1) - means yesterday, (7) - a week ago and so on.
__________________
Buy or sell traffic Here or Here

Last edited by mazafaka; 05-17-2004 at 02:11 AM..
mazafaka is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-17-2004, 02:20 AM   #4
mazafaka
Confirmed User
 
Join Date: Oct 2002
Posts: 148
damn

" haha123;" means "left curly brace"
__________________
Buy or sell traffic Here or Here
mazafaka is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-17-2004, 06:42 AM   #5
grannytgp
Confirmed User
 
Join Date: Aug 2002
Posts: 269
Quote:
Originally posted by mazafaka
<s.c.r.i.p.t.>
function DatePrint(days)
{
var today = new Date();
var theDate = new Date(today.valueOf()-days*86400000);
var day = theDate.getDate();
getmonth = theDate.getMonth();
var monthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
month = monthArray[getmonth];
var ds = '';
if (day < 10)
ds = '0';
document.write(month + " " + ds + day);
}
</s.c.r.i.p.t.>

<s.c.r.i.p.t.>DatePrint(1)</s.c.r.i.p.t.>


-----------------
(1) - means yesterday, (7) - a week ago and so on.
mazafaka - this works great, and with very little code which is a plus Thanks a bunch once again.
grannytgp is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.