View Full Version : How can i publish the date being in custom format

11-16-2012, 09:23 PM
This is my code

document.getElementById("demo").innerHTML = myDate.toDateString("m/dd/yy");

but the output is

Sat Jul 21 1990

I don't want the day of week (Sat) or the day number (21)

11-16-2012, 09:48 PM
You haven't provided the code that defines how the toDateString method you have added to dates is defined. From the look of that output it appears that it totally ignores the parameter you entered but without seeing the code there is no way to tell for certain.

If you are going to add a method for formatting the date the way you want rather than just joining the fields together then you ought to use one that works - see http://www.felgall.com/datemethods.htm for one alternative where myDate.format('n/d/y') will return the date in the format you want.

Old Pedant
11-16-2012, 10:19 PM
Ummm...he does *NOT* want the DAY to show. And he seems to want a 4-digit year and the month name abbreviated.

So should your method be invoked with myDate.format('M Y') ???

11-16-2012, 10:59 PM
when i do this

document.getElementById("demo").innerHTML = myDate.format('jS F, Y');

nothing displays

Old Pedant
11-16-2012, 11:17 PM
Did you download Felgall's code library???

rnd me
11-17-2012, 12:25 AM
You haven't provided the code that defines how the toDateString method you have added to dates is defined.

lol, i'll do it for him since HE didn't add it (brendan did):

new Date().toDateString == function toDateString() { [native code] }

you don't need a whole library to replace a few simple lines of code, that's like adding jQuery to alter document.title using $("title").html("hello")...

var d=new Date(),
s= [

alert(s); // === "11/16/12"

Old Pedant
11-17-2012, 12:38 AM
Except, again, he *SEEMED* to say he wants the NAME of the month and *NOT* the day of the month, at all.


var mnames = ["Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec" ];

var d = new Date();
alert( mnames[d.getMonth()] + " " + d.getFullYear() );

But who knows?

11-17-2012, 01:26 AM
Did you download Felgall's code library???

obviously not or the date would have displayed - I use that particular combination quite a lot myself, it was one of the main reasons i started creating that library.

Old Pedant
11-17-2012, 01:28 AM
(Actually, I think I knew the answer before I asked the question. I was being nice.)