...

View Full Version : Edit date script



steve6
01-20-2006, 04:10 PM
Could someone edit this script so the date is always 2 weeks infront of the actual date?

<script language="JavaScript">
<!--
var now = new Date();
var days = new Array(
'Sunday','Monday','Tuesday',
'Wednesday','Thursday','Friday','Saturday');
var months = new Array(
'January','February','March','April','May',
'June','July','August','September','October',
'November','December');
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;}
today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear()));
document.write(today);
//-->
</script>


Thanks

Kor
01-20-2006, 05:18 PM
Something like this?:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var now = new Date();
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var months = ['January','February','March','April','May','June','July','August','September','October','November',' December'];
var newdate=new Date(now.getFullYear(),now.getMonth(),now.getDate()-14);
var y=newdate.getFullYear(); var m=newdate.getMonth(); var d = newdate.getDate();
d<10?d='0'+d:null;
onload = function(){
document.getElementById('dat').firstChild.data=y+' '+months[m]+' '+d+' '+days[newdate.getDay()]
}
</script>
</head>
<body>
<div id="dat">&nbsp;</div>
</body>
</html>

steve6
01-20-2006, 07:06 PM
Yup, thats exactly what i was after, thanks. :D

Oricalos
01-09-2010, 11:46 AM
<script>

var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym=""+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write(dayarray[day]+", "+montharray[month]+" "+daym+", "+year)

</script>

Can someone please help me and edit this script so rather than it loading today's date, instead, I want it to load the upcoming Thursdays date.

E.G. At the time of this post, the date should read: Thursday, January 14, 2010.

Once the 14th passes, the date script would now read: Thursday, January 21, 2010 and so on, I just want it load upcoming Thursdays date only.

Philip M
01-09-2010, 12:42 PM
Here you are:-


<script type = "text/javascript">

var myDate = new Date();
var day = myDate.getDay();
var thurs = 4 - day; // Thursday is day 4
if (thurs < 0) {thurs = thurs + 7}
myDate.setDate(myDate.getDate() + thurs);
var year = myDate.getFullYear();
var day = myDate.getDay();
var month = myDate.getMonth(); // months in JavaScript are 0-11
var daym = myDate.getDate();
if (daym<10) {daym="0" + daym} // prefix 0
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write(dayarray[day]+", "+montharray[month]+" "+daym+", "+year)

</script>


But you should really have started a new thread rather than revive this ancient one.

"Utility is when you have one telephone, luxury is when you have two, opulance is when you have three, and paradise when you have none." - Doug Larson

Oricalos
01-09-2010, 01:20 PM
Here you are:-


<script type = "text/javascript">

var myDate = new Date();
var day = myDate.getDay();
var thurs = 4 - day; // Thursday is day 4
if (thurs < 0) {thurs = thurs + 7}
myDate.setDate(myDate.getDate() + thurs);
var year = myDate.getFullYear();
var day = myDate.getDay();
var month = myDate.getMonth(); // months in JavaScript are 0-11
var daym = myDate.getDate();
if (daym<10) {daym="0" + daym} // prefix 0
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write(dayarray[day]+", "+montharray[month]+" "+daym+", "+year)

</script>


But you should really have started a new thread rather than revive this ancient one.

"Utility is when you have one telephone, luxury is when you have two, opulance is when you have three, and paradise when you have none." - Doug Larson

I apologize, I wasn't sure which was the right thing to do. Thank you very much for the assistance Phillip M!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum