Re: Date Format

by "Stephanie Thrasher" <steph(at)omsoft.com>

 Date:  Tue, 4 Jun 2002 09:17:37 -0700
 To:  <hwg-languages(at)hwg.org>
 References:  kl19a mom kl19a2
  todo: View Thread, Original
David,

I think this is what you want.  The concatenation was a great idea.

if (date == 1 || date == 21 || date == 31) dateName = date + "st";
if (date == 2 || date == 22) dateName = date + "nd";
if (date == 3 || date == 23) dateName = date + "rd";
if (date > 3 && date < 21) dateName = date + "th";
if (date > 23 && date < 31) dateName = date + "th";



> Stephanie,
>
> Thanks for that code... it worked a treat ! I've uploaded a new version to
> the same URL...
>
> http://www.artiss71.fsworld.co.uk/date.html
>
> Now, the code isn't quite as efficient as it should be because a couple of
> the lines could easily have been concatonated together. How do you put
> multiple conditions within an "IF" statement in JS ?
>
> e.g. I'd like to put
>
> if (date == 1 or date == 21) dateName = date + "st";
>
> David.
>
> ----- Original Message -----
> From: "Stephanie Thrasher" <steph(at)omsoft.com>
> To: "David Artiss" <david(at)artiss.co.uk>; <hwg-languages(at)hwg.org>
> Sent: Monday, June 03, 2002 5:10 PM
> Subject: Re: Date Format
>
>
> > Hi David,
> >
> > I think this will do it:
> >
> > var date = now.getDate();
> > var dateName;
> >  if (date == 1) dateName = "1st";
> >  if (date == 2) dateName = "2nd";
> >  if (date == 3) dateName = "3rd";
> >  if (date == 4) dateName = "4th";
> >
> >
> > ...etc.
> >
> > document.write(dayName[now.getDay()] + ", " + monName[now.getMonth()] +
"
> "
> > + dateName);
> >
> > Stephanie
> >
> >
> >
> > > Hi !
> > >
> > > I think I'm suffering from more brain fade today. A while ago I got a
> > script
> > > from a site which displays the current date. It can be found at...
> > >
> > > http://www.artiss71.fsworld.co.uk/date.html
> > >
> > > It displays the date in the format "Monday, June 3". I'd like to make
> this
> > a
> > > little more user-friendly by adding the appropriate suffix onto the
end
> of
> > > the day - e.g. "Monday, June 3rd". However, I've been unable to work
out
> > > how. If anybody can assist it will be appreciated.
> > >
> > > David.
> > >
> > >
> > >
> >
>
>
>

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA