[thelist] JavaScript date problem

Syed Zeeshan Haider zeeshan_paki at yahoo.com
Thu Jan 3 14:09:32 CST 2002

Hi Kristina,
I have read your post and replies to it. None of those scripts, which were
sent to you satisfied me. Therefore, I have created a script for you. It
gives three messages according to the time.
Those Messages are:
Good Morning            0000 hours to 1200 hours
Good Afternoon          1200 hours to 1800 hours
Good Evening             1800 hours to 0000 hours
Other part of the message is same as your requirement requires. If you
encounter any problem please tell me so that I can remove that problem from
the script. I have checked this script with IE 5.5 and NN 4.77 and it works
with both in Windows environment.
Here is the script. Copy and paste to use it.

<script language="JavaScript">
var pam, greet, exten
var todaysDate=new Date()
var theDate=todaysDate.getDate()
var theDay=todaysDate.getDay()
var theMonth=todaysDate.getMonth()
var theYear=todaysDate.getFullYear()
var theHour=todaysDate.getHours()
var theMinute=todaysDate.getMinutes()
pam="am";greet="Good Morning"
greet="Good Afternoon"
greet="Good Evening"
if(theHour==0) // when it is midnight
theHour=12,pam="am";greet="Good Morning"
var thisDay=new
var thisMonth=new
var exts=new Array("th","st","nd","rd","th","th","th","th","th","th")
var strDate=theDate.toString()
var charNo=strDate.charAt(eval(strDate.length-1));parseInt(charNo)
function assignExt(No)
if(theDate>9 && theDate<21)
document.write(greet+" it's "+theHour+":"+theMinute+" "+pam+" on
"+thisDay[theDay]+" the "+theDate+exten+" of "+thisMonth[theMonth]+"

Don't hesitate to tell me if this script produces any problems. Although I
have spent enough time to check it but it is time dependent, therefore, it
is a little difficult to check it for all situations in a small span of
Syed Zeeshan Haider,

----- Original Message -----
Message: 17
Date: Wed, 2 Jan 2002 16:19:40 +0000
From: kristina <kristina at kfx-design.co.uk>
Reply-To: kristina <kristina at kfx-design.co.uk>
To: thelist at lists.evolt.org
Subject: [thelist] JavaScript date problem
Reply-To: thelist at lists.evolt.org

Hello all, and Happy New Year to all

  I am struggling with a JavaScript that needs to display the date and
  time in a certain format!

  The client wants the date on his website eg:
  Good Afternoon it's 4:14 pm on Wednesday the 2nd of January 2002

  (thanks to PPK's site) I can get

  Good Afternoon it's 4:14 pm on Wednesday the 2 of January 2002

  My problem is making the nd's, st's, rd's and th's appear....

  Is this possible, as it seems to be the one thing lacking in all the
  scripts I've scoured.  My guess is I'd have to create a new array
  with all the appropriate 1st 2nd 3rd in up to 31st - but after that
  I don't know what to do.


kristina at kfx-design.co.uk

Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

More information about the thelist mailing list