Connecting Tech Pros Worldwide Help | Site Map

sysdate function

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 09:58 AM
Max
Guest
 
Posts: n/a
Default 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



  #2  
Old July 20th, 2005, 09:58 AM
Lee
Guest
 
Posts: n/a
Default 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:
http://www.merlyn.demon.co.uk/js-dates.htm

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

  #3  
Old July 20th, 2005, 09:59 AM
Max
Guest
 
Posts: n/a
Default Re: sysdate function

doesn't help much
"Lee" <REM0VElbspamtrap@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]


  #4  
Old July 20th, 2005, 09:59 AM
Sean Jorden
Guest
 
Posts: n/a
Default 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" <REM0VElbspamtrap@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.getFullYear();
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).substr(2, 2);
s["yyyy"] = y;
var re = /(.*)(\W|^)(d|dd|ddd|dddd|M|MM|MMM|MMMM|y|yy|yyyy)( \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
  #5  
Old July 20th, 2005, 10:00 AM
Dr John Stockton
Guest
 
Posts: n/a
Default Re: sysdate function

JRS: In article <Xns93EB1278DD2B0sjorden@198.80.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$dt9$1@s1.read.news.oleane.net:
>[color=green]
>> doesn't help much
>> "Lee" <REM0VElbspamtrap@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.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
  #6  
Old July 20th, 2005, 10:00 AM
Sean Jorden
Guest
 
Posts: n/a
Default Re: sysdate function

Dr John Stockton <spam@merlyn.demon.co.uk> wrote in
news:caGb6bFk6iV$EwO2@merlyn.demon.co.uk:

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

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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.