sysdate function

M

Max

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
 
L

Lee

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

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

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.
 
S

Sean Jorden

doesn't help much


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

Dr John Stockton

JRS: In article <[email protected]>, seen in
news:comp.lang.javascript said:
<html>
... ... ... ...
</html>

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()))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,083
Messages
2,570,591
Members
47,212
Latest member
RobynWiley

Latest Threads

Top