473,378 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Y2K problem with script?

Below is an old count-up script that displays ok in MSIE with a bit of
experimenting, but NS shows negative values that make no sense. Anyone
know how to make it work ok in both?

=== Cut ===
<script language=JavaScript>
/*
Date Count-up 1.0
(C) Copyright 1996 Ben Harold
All rights Reserved
Feel free to use this script in your page under the folling
conditions :
1. Do not modify this script in any way (besides
following the
configuration directions) without my consent
2. Mail me at bh*****@indyunix.iupui.edu if you use it
3. I am not held responsible for any thing that this
script may
do to your computer
*/

// Configuration Directions
// Don't change this
// This makes a date variable that is used to get the current date

today = new Date()

// Don't change these

// These get the current year, month, and date

var thisyear = today.getYear()
var thismonth = today.getMonth()
var thisdate = today.getDate()

// Change these
// These set the year, month, and date to count from
// NOTICE : var thatmonth should be a number between 0 and 11, not 1
and 12

var thatyear = 1995
var thatmonth = 10
var thatdate = 15

// Change this
// This is what the browser will display just before the years, months,
and dates
// NOTICE : make sure that there is a space after the last word of var
prestring

var prestring = " "

// Don't change these
// These set variables used by other parts of the script

var fromyears = (thisyear - thatyear)
var datenumber = (thisdate + thatdate)

// Don' change this
// This figures out how many days there are in the current month

if (thismonth == 0)
monthdates = (31)
else if (thismonth == 1)
monthdates = (28)
else if (thismonth == 2)
monthdates = (31)
else if (thismonth == 3)
monthdates = (30)
else if (thismonth == 4)
monthdates = (31)
else if (thismonth == 5)
monthdates = (30)
else if (thismonth == 6)
monthdates = (31)
else if (thismonth == 7)
monthdates = (31)
else if (thismonth == 8)
monthdates = (30)
else if (thismonth == 9)
monthdates = (31)
else if (thismonth == 10)
monthdates = (30)
else if (thismonth == 11)
monthdates = (31)

// Don't change this
// This figures out how many years it has been since thatyear

if (fromyears == 0)
yearssince = (prestring)

else if (fromyears == 1)
yearssince = (prestring + " year")

else yearssince = (prestring + fromyears + " years")

// Don't change this
// This figures out how many dates it has been since thatdate

if (thisdate > thatdate)
predatessince = (thisdate - thatdate)
else predatessince = (thisdate + monthdates - thatdate)
if (predatessince == 0)
datessince = ("no days.")
else if (predatessince == 1)
datessince = ("1 day.")
else datessince = (predatessince + " days.")

// Don't change this
// This figures out how many months it has been since thatmonth

if (thisyear > thatyear) {
if (thismonth >= thatmonth)
premonthssince = (thismonth -
thatmonth)
else premonthssince = (12 + thismonth -
thatmonth)
}

else premonthssince = (thismonth - thatmonth)

if (monthdates < datenumber)
premonthssincetwo = (premonthssince + 1)
else premonthssincetwo = (premonthssince)
if (premonthssincetwo == 0)
monthssince = (" ")
else if (premonthssincetwo == 1)
monthssince = ("1 month")
else monthssince = (premonthssincetwo +
"months")

// Don't change these
// These figure out what type of punctuation to use in the final
message

if (yearssince == prestring)
commaone = (" ")
else {
if (monthssince == " ")
(commaone = " and ")
else commaone = (", ")
}

if (commaone == " and ")
commatwo = (" ")
else if (commaone == ", ")
commatwo = (" and ")
else if (yearssince == prestring) {
if (monthssince == " ")
(commatwo = " ")
else commatwo = (" and ")
}

// Don't change this
// This assembles the final message

var finalstring = ""
finalstring += (yearssince)
finalstring += (commaone)
finalstring += (monthssince)
finalstring += (commatwo)
finalstring += (datessince)

// Don't change this
// This prints the final message to the browser screen

document.write(finalstring)
</script>
=== Cut ===
Kari Suomela

KARICO Business Services
Toronto, ON Canada
http://www.karico.ca

.... Never straighten a good waistline.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Sep 29 '05 #1
4 1540
no**@of.your.biz.nes wrote:
Below is an old count-up script that displays ok in MSIE with a bit of
experimenting, but NS shows negative values that make no sense. Anyone
know how to make it work ok in both?
There have been two threads in the last few days on this, search for
getFullYear and sort by date.

"Date problem in Opera"
<URL:http://groups.google.co.uk/group/comp.lang.javascript/browse_frm/thread/3fad1afb8207408b/5ff2ae7a62b8b319?q=getFullYear&rnum=1&hl=en#5ff2ae 7a62b8b319>

"Who's fault: different displays of date"
<URL:http://groups.google.co.uk/group/comp.lang.javascript/browse_frm/thread/eff514c740a32ae2/a5e8b6192b35b610?q=getFullYear&rnum=2&hl=en#a5e8b6 192b35b610>
[...]
// These get the current year, month, and date

var thisyear = today.getYear()


Here's your problem ----------^^^^^^^

Use getFullYear(), but be aware that very old browsers will only support
getYear().

That caveat is added because if a date function misbehaves for any
reason, a visitor's confidence in your site is shaken - even a very
small number of failures may be unacceptable.

[...]

--
Rob
Sep 29 '05 #2
Lee
no**@of.your.biz.nes said:
// Don't change these

// These get the current year, month, and date

var thisyear = today.getYear()


Change that to:

var thisyear = today.getFullYear();

Sep 29 '05 #3
Thursday September 29 2005 16:10, Lee wrote to All:
var thisyear = today.getYear()


L> Change that to:

L> var thisyear = today.getFullYear();

Thanks to all who replied. Works ok now.
KS

KARICO Business Services
Toronto, ON Canada
http://www.karico.ca

.... Sound and fury, signifying nothing.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Sep 30 '05 #4
JRS: In article <Go****************************@of.your.biz.nes> , dated
Thu, 29 Sep 2005 18:47:19, seen in news:comp.lang.javascript,
no**@of.your.biz.nes <DA******************@your.bis.nes> posted :
Below is an old count-up script that displays ok in MSIE with a bit of
experimenting, but NS shows negative values that make no sense. Anyone
know how to make it work ok in both?


DO NOT just change getYear to getFullYear; the code would be rubbish
even if it were not bloated, though the results may be correct most of
the time (I don't see allowance for Leap Years).

Code posted to News should be executable as is, which means that it
should not be wrapped by the posting process.

Read the newsgroup FAQ; see below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 30 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Allen | last post by:
I am trying to add an additional photo/hyperlink to the company web site (I didn't create it) without any luck. The mouseover feature 'highlights' pics by swapping them with another pic using this...
7
by: David. E. Goble | last post by:
Hi all; I have the following files; index.html, sigsheader.js, sigsboby.js, smilesbody.js and smiles.js. The sourse is below. The page displays two manual slide shows... Each slideshow has a set...
62
by: TheShadow1 | last post by:
safetyTips - this array is in here.js ...
55
by: drhowarddrfine | last post by:
I'm working on a web site that could use some control using js but am concerned about what problems I may have with potential users having their js turned off. Has anyone had any serious problems...
9
by: David. E. Goble | last post by:
Arrrh! some buttons work while others don't, but I can't see why. I have tried comparing the files that do work, with the ones that don't. But to no help. The funny thing is the parts that work...
7
by: sck10 | last post by:
Hello, I have the following sub in a class in my "App_Code" directory. The script is for setting focus on a particular control, but I get the error, "Name ClientScript Not declared". Also, I am...
1
by: Neo Geshel | last post by:
I am having conflicting results with two pieces of identical code. One is an insert, the other is an update to a db. The first code, which works, is this: Sub Add3_Click(sender As Object, e As...
10
by: ellie2905 | last post by:
Hello, I am new to this forum and I am glad I found it because it seems that it will help me with my problem.I have creates a site using jsf components like grid panels and buttons.In the mozilla...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.