Format date

  • Thread starter Thread starter SS
  • Start date Start date
S

SS

Hi

I have a form that goes to a database but the date if format as
Month/Day/Year.

Is there a script I can put into the html to make it format the date as
Day/Month/Year

Cheers Shona
 
SS said:
Hi

I have a form that goes to a database but the date if format as
Month/Day/Year.

Is there a script I can put into the html to make it format the date
as Day/Month/Year

Cheers Shona

Here are some different examples
<html>
<body>
<script type="text/javascript">
function checkTime(i) {
if (i < 10)
i="0" + i
return i
}
var d=new Date()
var day=d.getDate()
var month=d.getMonth() + 1
var year=d.getFullYear()
document.write(day + "." + month + "." + year)
document.write("<br /><br />")
document.write(year + "/" + month + "/" + day)
document.write("<br /><br />")
document.write(checkTime(day) + "/" + checkTime(month) + "/" + year)
</script>
</body>
</html>

The results are
4.8.2006

2006/8/4

04/08/2006

P.S. This is courtesy of w3schools:
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_datedate

Bu thsiu relies on seting the date via Javascript
i.e. var d=new Date()

In what format does the date come back from the database ?
It may be a string, but I have tested this
var d=new Date("08/04/2006")
and it also works (where this format means 4th August 2006)
 
Hi

Sorry I think you misuderstood me. I have a form which when submitted adds
the Timestamp to the database which when viewed is in the format
month/day/year even though the field within the database is set to short
date eg 19/6/1994

Thanks Shona
 
Back
Top