17 replies [Last post]
rmcivo1
Offline
Enthusiast
Shropshire | Shrewsbury
Last seen: 9 years 2 weeks ago
Shropshire | Shrewsbury
Joined: 2003-12-05
Posts: 115
Points: 0

Would this kind of Array work for the Date

var Today=new date()

var Date= New Array
("1st","2nd","3rd","4th" etc)

</HEAD>

document.write(Date[Today.getDate])

Thank you
Rees

The Cyber World

Tags:
dJomp
dJomp's picture
Offline
Enthusiast
Last seen: 4 years 9 weeks ago
Joined: 2003-03-23
Posts: 422
Points: 0

Javascript Date Array

Not a big javascript user... but...

Common practice would tell me that the first element in the date array ('1st') would be assigned to 0. That's computers for you.

Presuming the Today.getDate function returns a number between 1 and 31, then the solution will work, if you add something at the start of the array for the 0 element.

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.

rmcivo1
Offline
Enthusiast
Shropshire | Shrewsbury
Last seen: 9 years 2 weeks ago
Shropshire | Shrewsbury
Joined: 2003-12-05
Posts: 115
Points: 0

Javascript Date Array

what I was trying to day was can you do the "The Date" using a Javascript Array. And how

Sorry about the mis-undersatnding
Rees

The Cyber World

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 weeks 6 days ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5342
Points: 2963

Javascript Date Array

Hi rmcivo1,
Your pretty close.
Add () to getDate eg [Today.getDate()]
New should be "new" lowercase n.
It would be best to use a different name for your Date array maybe date_array or something so its not confused with date().

Hope that helps

rmcivo1
Offline
Enthusiast
Shropshire | Shrewsbury
Last seen: 9 years 2 weeks ago
Shropshire | Shrewsbury
Joined: 2003-12-05
Posts: 115
Points: 0

Javascript Date Array

Thank you Tony, You have helped me alot

Thank you Ever so Much
Rees

Slight Prolem Can u help

HEAD

var todays_Date = new Array();
("1st","2nd","3rd","4th","5th", "6th","7th","8th","9th","10th", "11st","12nd","13rd","14th","15th", "16th","17th","18th","19th","20th", "21st","22nd","23rd","24th","25th", "26th","27th","28th","29th","30th","31st");

HTML
todays_Date[Today.gettodays_Date()]

The Cyber World

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 weeks 6 days ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5342
Points: 2963

Javascript Date Array

Hi rmcivo1,
Because the first element in the array is [0] you need to either add an element to the beginning of the array or remove one from the index.
[Today.getDate()-1]

Hope that helps

rmcivo1
Offline
Enthusiast
Shropshire | Shrewsbury
Last seen: 9 years 2 weeks ago
Shropshire | Shrewsbury
Joined: 2003-12-05
Posts: 115
Points: 0

Javascript Date Array

Hiya it doesnt seem to work, Could you have a look please Smile

[/code]

The Cyber World

dJomp
dJomp's picture
Offline
Enthusiast
Last seen: 4 years 9 weeks ago
Joined: 2003-03-23
Posts: 422
Points: 0

Javascript Date Array

I don't know the exact cure... but...

You want EITHER a "0" at the start of the array; OR -1 in the printing bit of script.

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 weeks 6 days ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5342
Points: 2963

Javascript Date Array

Hi rmcivo1,
It works for me.Smile
document.write(todays_Date[Today.getDate()-1]);

rmcivo1
Offline
Enthusiast
Shropshire | Shrewsbury
Last seen: 9 years 2 weeks ago
Shropshire | Shrewsbury
Joined: 2003-12-05
Posts: 115
Points: 0

It doesnt Seem to Work

I get the outcome as "Undefined"

The Cyber World

dJomp
dJomp's picture
Offline
Enthusiast
Last seen: 4 years 9 weeks ago
Joined: 2003-03-23
Posts: 422
Points: 0

Javascript Date Array

So do I on that sample...

The array isn't defined correctly. Double-check that.

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.

rmcivo1
Offline
Enthusiast
Shropshire | Shrewsbury
Last seen: 9 years 2 weeks ago
Shropshire | Shrewsbury
Joined: 2003-12-05
Posts: 115
Points: 0

Javascript Date Array

I dont know where to start because I am only a beginner

The Cyber World

dJomp
dJomp's picture
Offline
Enthusiast
Last seen: 4 years 9 weeks ago
Joined: 2003-03-23
Posts: 422
Points: 0

Javascript Date Array

var Date = new Array();
("0","1st"...

var Month = new Array
("January","February"...

Spot the difference! I think that might be the problem.

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 weeks 6 days ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5342
Points: 2963

Javascript Date Array

Hi rmcivo1,

Quote:
var todays_Date = new Array();
("1st","2nd","3rd","4th","5th", "6th","7th","8th","9th","10th", "11st","12nd","13rd","14th","15th", "16th","17th","18th","19th","20th", "21st","22nd","23rd","24th","25th", "26th","27th","28th","29th","30th","31st");

should be var todays_Date = new Array("1st","2nd","3rd","4th","5th", "6th","7th","8th","9th","10th", "11st","12nd","13rd","14th","15th", "16th","17th","18th","19th","20th", "21st","22nd","23rd","24th","25th", "26th","27th","28th","29th","30th","31st");

rmcivo1
Offline
Enthusiast
Shropshire | Shrewsbury
Last seen: 9 years 2 weeks ago
Shropshire | Shrewsbury
Joined: 2003-12-05
Posts: 115
Points: 0

Sorry to be a pain

Sorry to be a pain, but the dam thing aint working.

The Cyber World

dJomp
dJomp's picture
Offline
Enthusiast
Last seen: 4 years 9 weeks ago
Joined: 2003-03-23
Posts: 422
Points: 0

Javascript Date Array

It's because you've changed the code.

Change

								document.write(Todays_Date[Today.getTodays_Date()-1])

back to
								document.write(Todays_Date[Today.getDate()-1])

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.

rmcivo1
Offline
Enthusiast
Shropshire | Shrewsbury
Last seen: 9 years 2 weeks ago
Shropshire | Shrewsbury
Joined: 2003-12-05
Posts: 115
Points: 0

Thank you

Thank you Tonyand dJomp, I dont know how to thank you enough

You have made Javascript seem easy
Thank you
Rees

The Cyber World

rmcivo1
Offline
Enthusiast
Shropshire | Shrewsbury
Last seen: 9 years 2 weeks ago
Shropshire | Shrewsbury
Joined: 2003-12-05
Posts: 115
Points: 0

Javascript Date Array

could I make an javascipt using "if then Else"

Like if Day==Monday then
document.write(string)
if day==tuesday
document.write(different string)

Thankyou
Rees

The Cyber World