Need some help dynamically setting day/date

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith

    Need some help dynamically setting day/date

    I don't know javascript and was wondering if someone might give me a simple
    script to dynamically display the day and date in the following format:

    Sunday, October 12, 2003

    Any help would be appreciated -- thanks. I'll give you credit for the script
    in the comments if you want.


  • Ivo

    #2
    Re: Need some help dynamically setting day/date


    "Keith" <no@spam.com> wrote in message
    news:ZGhib.6491 8$nU6.11831197@ twister.nyc.rr. com...[color=blue]
    > I don't know javascript and was wondering if someone might give me a[/color]
    simple[color=blue]
    > script to dynamically display the day and date in the following format:
    >
    > Sunday, October 12, 2003
    >
    > Any help would be appreciated -- thanks. I'll give you credit for the[/color]
    script[color=blue]
    > in the comments if you want.
    >[/color]

    This bit of code will put the current date at the location within the body
    where you choose to put this script:

    <script type="text/javascript"><!--
    var mydate=new Date();
    var year=mydate.get FullYear();if (!year) year=mydate.get Year()+2000;
    var day=mydate.getD ay();
    var month=mydate.ge tMonth();
    var daym=mydate.get Date();
    var dayarray=new Array("Sun","Mo n","Tues","Wedn es","Thurs","Fr i","Satur")
    var montharray=new
    Array("January" ,"February","Ma rch","April","M ay","June","Jul y","August","Se p
    tember","Octobe r","November"," December")
    window.status=d ayarray[day]+"day, "+daym+" "+montharra y[month]+", "+year;
    // --></script>


    Comment

    • The Keith

      #3
      Re: Need some help dynamically setting day/date

      thanks but I just found this one--works fine:




      "Ivo" <no@thank.you > wrote in message
      news:3f89ae1b$0 $440$1b62eedf@n ews.wanadoo.nl. ..[color=blue]
      >
      > "Keith" <no@spam.com> wrote in message
      > news:ZGhib.6491 8$nU6.11831197@ twister.nyc.rr. com...[color=green]
      > > I don't know javascript and was wondering if someone might give me a[/color]
      > simple[color=green]
      > > script to dynamically display the day and date in the following format:
      > >
      > > Sunday, October 12, 2003
      > >
      > > Any help would be appreciated -- thanks. I'll give you credit for the[/color]
      > script[color=green]
      > > in the comments if you want.
      > >[/color]
      >
      > This bit of code will put the current date at the location within the body
      > where you choose to put this script:
      >
      > <script type="text/javascript"><!--
      > var mydate=new Date();
      > var year=mydate.get FullYear();if (!year) year=mydate.get Year()+2000;
      > var day=mydate.getD ay();
      > var month=mydate.ge tMonth();
      > var daym=mydate.get Date();
      > var dayarray=new Array("Sun","Mo n","Tues","Wedn es","Thurs","Fr i","Satur")
      > var montharray=new
      >[/color]
      Array("January" ,"February","Ma rch","April","M ay","June","Jul y","August","Se p[color=blue]
      > tember","Octobe r","November"," December")
      > window.status=d ayarray[day]+"day, "+daym+" "+montharra y[month]+", "+year;
      > // --></script>
      >
      >[/color]


      Comment

      • Dr John Stockton

        #4
        Re: Need some help dynamically setting day/date

        JRS: In article <3f89ae1b$0$440 $1b62eedf@news. wanadoo.nl>, seen in
        news:comp.lang. javascript, Ivo <no@thank.you > posted at Sun, 12 Oct 2003
        21:40:14 :-
        [color=blue]
        >var year=mydate.get FullYear();if (!year) year=mydate.get Year()+2000;[/color]

        There is no point in coding for the attempted use of a possibly-present
        method if you are going to provide code for an alternative always-
        available method anyway - the user has to download both, and you need to
        test both.

        In fact, AIUI, getFullYear is JS 1.2, which was implemented in version 4
        of two major browsers, and so is probably safe enough.

        If I simulate the absence of getFullYear by mis-spelling it, I get an
        error message, that year is undefined.

        If I omit that statement, the if part results in an error message, that
        year is undefined.

        If I do just year=mydate.get Year()+2000; I get 4003; getYear()
        gave 2003. It may be that, wherever getFullYear does not exist,
        getYear() gives Year%100; but I rather doubt it and expect it to give
        Year-1900.

        I believe year = mydate.getYear( )%1900 + 1900 to be safe until
        end 3799, but unnecessary; and year = mydate.getYear( )%100 + 2000
        to be OK until end 2099. Read the FAQ.

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

        Comment

        Working...