Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formating dates

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
Hi,

Yesterday I was helped with a date function to get the results I needed, see below. My problem now is formatting the dates in to this format dd/mm/yyy. I have tried everything I could find on the internet but everything I used cam back with errors.

Could some show me the way to structure the dateformat() function to get the date formatted like dd/mm/yyyy.

Thanks in advance.

Code:
var d=new Date()

d.setDate(d.getDate()+9)
alert(d.toString()) //shows today's date plus 9 days
 
Here is a html page example and the alert(dateFormat(d, "dd/mm/yyyy")) does not work and give an object expected error.

Code:
<html>

<head>
<script>

var d=new Date()

dateFormat(d, "dd/mm/yyyy");



function datform(){

d.setDate(d.getDate()+9)

alert(dateFormat(d, "dd/mm/yyyy")) // THIS GIVES AN ERROR OF OBJACT EXPECTED

alert(d.toString())


}

</script>
</head>
<body onload="datform()">



</body>

</html>
 
Hi

With that effort you can name your function for example craigward_wants_format(). While neither dateFormat() nor craigward_wants_format() is defined, you will get the same error.

Feherke.
 
Sorry, i am not understanding this. If you take out this from the code the function works fine. What i am asking i thinkisa simple date function that can be applied.


alert(dateFormat(d, "dd/mm/yyyy")) // THIS GIVES AN ERROR OF OBJACT EXPECTED
 
I don't think "dateFormat" is a proper javascript function. Have you defined that function elsewhere?

_________________
Bob Rashkin
 
No i have not defined that function anywhere, i thought it was built in.
 
Thanks for that, i am playing with it but can't get it working yet. I'm not great with javascript. Will post back once i have played some more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top