sysdate function

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

    sysdate function

    I need a little javascript function that returns the date of today in the
    format dd/mm/yyyy
    example:
    September 2, 2003 ==> 02/09/2003

    For control reasons, it cannot be 2/9/2003 or 02/9/2003 or 2/09/2003 but
    only 02/09/2003

    December 14, 2003 ==> 14/12/2003

    Thanks


  • Lee

    #2
    Re: sysdate function

    Max said:[color=blue]
    >
    >I need a little javascript function that returns the date of today in the
    >format dd/mm/yyyy
    >example:
    >September 2, 2003 ==> 02/09/2003
    >
    >For control reasons, it cannot be 2/9/2003 or 02/9/2003 or 2/09/2003 but
    >only 02/09/2003
    >
    >December 14, 2003 ==> 14/12/2003[/color]

    Per the FAQ for this newsgroup, you should look here:


    You might also consider using the format 2003-12-14, if possible.

    Comment

    • Max

      #3
      Re: sysdate function

      doesn't help much
      "Lee" <REM0VElbspamtr ap@cox.net> a écrit dans le message news:
      bj32up04k5@drn. newsguy.com...[color=blue]
      > Max said:[color=green]
      > >
      > >I need a little javascript function that returns the date of today in the
      > >format dd/mm/yyyy
      > >example:
      > >September 2, 2003 ==> 02/09/2003
      > >
      > >For control reasons, it cannot be 2/9/2003 or 02/9/2003 or 2/09/2003 but
      > >only 02/09/2003
      > >
      > >December 14, 2003 ==> 14/12/2003[/color]
      >
      > Per the FAQ for this newsgroup, you should look here:
      > http://www.merlyn.demon.co.uk/js-dates.htm
      >
      > You might also consider using the format 2003-12-14, if possible.
      >[/color]


      Comment

      • Sean Jorden

        #4
        Re: sysdate function

        "Max" <cefernan@cgey. com> wrote in
        news:bj45mq$dt9 $1@s1.read.news .oleane.net:
        [color=blue]
        > doesn't help much
        > "Lee" <REM0VElbspamtr ap@cox.net> a écrit dans le message news:
        > bj32up04k5@drn. newsguy.com...[color=green]
        >> Max said:[color=darkred]
        >> >
        >> >I need a little javascript function that returns the date of today
        >> >in the format dd/mm/yyyy
        >> >example:
        >> >September 2, 2003 ==> 02/09/2003[/color][/color][/color]


        <html>
        <head></head>
        <body>
        <script>
        function formatDate(date ,frm)
        {
        var str = new String(frm);
        var m = date.getMonth() ;
        var d = date.getDate();
        var y = date.getFullYea r();
        var w = date.getDay();
        var s = new Array();
        s["d"] = d;
        s["dd"] = (d < 10) ? ("0" + d) : d;
        s["M"] = 1+m;
        s["MM"] = (m < 9) ? ("0" + (1+m)) : (1+m);
        s["y"] = y;
        s["yy"] = new String(y).subst r(2, 2);
        s["yyyy"] = y;
        var re = /(.*)(\W|^)(d|dd |ddd|dddd|M|MM| MMM|MMMM|y|yy|y yyy)(\W|$)(.
        *)/;
        while (re.exec(str) != null) {
        str = RegExp.$1 + RegExp.$2 + s[RegExp.$3] + RegExp.$4 +
        RegExp.$5;
        }
        return str;
        }

        document.write( formatDate(new Date(),'dd/MM/yyyy'));

        </script>
        </body>
        </html>



        --
        In theory there is no difference between theory and practice. In practice
        there is. - YB

        Comment

        • Dr John Stockton

          #5
          Re: sysdate function

          JRS: In article <Xns93EB1278DD2 B0sjorden@198.8 0.55.250>, seen in
          news:comp.lang. javascript, Sean Jorden <s_j_o_r_d.e.n@ no.spam.n_o_r_a .d.a.com>
          posted at Wed, 3 Sep 2003 07:49:46 :-[color=blue]
          >"Max" <cefernan@cgey. com> wrote in
          >news:bj45mq$dt 9$1@s1.read.new s.oleane.net:
          >[color=green]
          >> doesn't help much
          >> "Lee" <REM0VElbspamtr ap@cox.net> a écrit dans le message news:
          >> bj32up04k5@drn. newsguy.com...[color=darkred]
          >>> Max said:
          >>> >
          >>> >I need a little javascript function that returns the date of today
          >>> >in the format dd/mm/yyyy
          >>> >example:
          >>> >September 2, 2003 ==> 02/09/2003[/color][/color]
          >
          >
          ><html>
          > ... ... ... ...
          ></html>[/color]

          But he specifically requested a little function.

          function LZ(x) {return(x<0||x> 9?"":"0")+x}

          function formatDate(date ) {
          with (date) return LZ(getDate())+'/'+LZ(getMonth() +1)+'/'+getFullYear()
          }

          document.write( formatDate(new Date()))

          --
          © 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

          • Sean Jorden

            #6
            Re: sysdate function

            Dr John Stockton <spam@merlyn.de mon.co.uk> wrote in
            news:caGb6bFk6i V$EwO2@merlyn.d emon.co.uk:

            [color=blue]
            >
            > But he specifically requested a little function.
            >[/color]

            sorry, I don't like non-reusable code.

            Comment

            Working...