Connecting Tech Pros Worldwide Help | Site Map

sysdate function

  #1  
Old July 20th, 2005, 10:58 AM
Max
Guest
 
Posts: n/a
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, 10:58 AM
Lee
Guest
 
Posts: n/a

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, 10:59 AM
Max
Guest
 
Posts: n/a

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, 10:59 AM
Sean Jorden
Guest
 
Posts: n/a

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, 11:00 AM
Dr John Stockton
Guest
 
Posts: n/a

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, 11:00 AM
Sean Jorden
Guest
 
Posts: n/a

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.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between current_date & sysdate function? sajithamol answers 1 July 13th, 2007 06:35 AM
Calling a custom Oracle function via PDO Anthony Smith answers 1 March 18th, 2007 06:15 PM
Automated testing | How to "force" GETDATE() function to return specific value? Konstantin Zakharenko answers 2 July 20th, 2005 03:10 AM
Statement returing True/False in decode() function Walt answers 1 July 19th, 2005 10:01 PM