Closed Thread Icon

Preserved Topic: Date Script (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18537" title="Pages that link to Preserved Topic: Date Script (Page 1 of 1)" rel="nofollow" >Preserved Topic: Date Script <span class="small">(Page 1 of 1)</span>\

 
Dark
Neurotic (0) Inmate
Newly admitted
posted posted 12-30-2001 15:29

Ok I know

<script language="JavaScript"><!--
var date = new Date();
var d = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;

document.write(month + "/" + day + "/" + year);
//--></script>


Will give me a readout of month/day/year like this "12/30/2001"
but what would I do if I wanted "12.30.01" ??

I know I change document.write(month + "/" + day + "/" + year);
to . . . . . . . . . . .document.write(month + "." + day + "." + year);

To get a [.] instead of a [/], but how do I change 2001 to 01

I mean what do I change in var year = (yy < 1000) ? yy + 1900 : yy; to get that?



:: Nothing Real Can Be Threatened. Nothing Unreal Exists. ::




[This message has been edited by Dark (edited 12-30-2001).]

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 12-30-2001 17:24

i dont know the exact syntax, but you can always use the substring function to get certain characters of a string.



StereoType
Bipolar (III) Inmate

From: the plushdjungle
Insane since: Oct 2001

posted posted 12-30-2001 17:44

I'm sure there is a simple way to do it "the right way", but why not do like this:
var year = 02;
it only changes once a year, you know. You have a whole year to find out "the right way" now!






[This message has been edited by StereoType (edited 12-30-2001).]

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 12-30-2001 20:17

You could also subtract 2000 from the date.

Best bet would be to substring the date. Treat it as a string makes it easier to manipulate.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 12-30-2001 21:24

var yy = date.getYear();
yy = (yy < 1000) ? yy + 1900 : yy; // this line shouldn't be necessary for any correct implementation of the Date object, i don't know why they put it there
var year = yy.substr(yy.length-2);

Dark
Neurotic (0) Inmate
Newly admitted
posted posted 12-30-2001 22:14

I can't seem to get it to work right......

If I replace var year = (yy < 1000) ? yy + 1900 : yy;

with...

var year = yy.substr(yy.length-2);

the script has an error stating

quote:
"This Object doesn't support this property or method."



I am probally not using the substring right or something.



:: Nothing Real Can Be Threatened. Nothing Unreal Exists. ::

[This message has been edited by Dark (edited 12-30-2001).]

Dark
Neurotic (0) Inmate
Newly admitted
posted posted 12-30-2001 22:53

Well for now I am going to put var year = '02'; ,but I would still like to get year part of the script working.

allmost forget to put the ' ' in 02, heh

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 12-31-2001 00:20

Don't *replace* the second line. Just use the full three lines of code I showed you.

Try changing the third one to

var year = (yy+"").substr((yy+"").length-2);

to remove the error. I'm not sure exactly what went wrong, but this should fix it.

Dark
Neurotic (0) Inmate
Newly admitted
posted posted 12-31-2001 02:04

hey that last one worked like a charm!

Thanks Slime =)


GRUMBLE,StereoType,WarMage- Thanks





:: Nothing Real Can Be Threatened. Nothing Unreal Exists. ::

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 12-31-2001 02:31

About using "date.getYear()"...you may want to read this

Later,
C:\

Dark
Neurotic (0) Inmate
Newly admitted
posted posted 12-31-2001 02:52

Thanks bud, that was really helpful =)

Dark
Neurotic (0) Inmate
Newly admitted
posted posted 01-01-2002 16:08

Sweet when 2002 hit the script change it perfectly slime!!!! Today's date is pretty wierd thought 1.01.02 just sounds and looks wierd, heh


:: Nothing Real Can Be Threatened. Nothing Unreal Exists. ::

« BackwardsOnwards »

Show Forum Drop Down Menu