![]() |
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. |
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)) |
<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. |
damn
" haha123;" means "left curly brace" |
Quote:
|
All times are GMT -7. The time now is 11:58 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123