View Full Version : Get year in two digits?

11-13-2003, 09:52 AM
How to get year in two digits ? Example for 2003 to get 03 ?
I use:

var year=mydate.getYear()

but this returns four digits year ?

11-13-2003, 09:56 AM
You don't want this bug to resurface again. Use 4 digit years.

09-29-2006, 08:32 AM
I have looked and found that most people know the answer but don't want to give it away because they prefer to lecture about how data should be accurate and that dates shuold have four digits etc. etc.

My employer wants the date DD/MM/YY so that's the code I give him, here it is:

theDate = new Date();
document.write theDate.getYear().toString().slice(2);

*Use the above if the you KNOW the date is going to be 2000 or greater otherwise use:

theDate = new Date();
document.write theDate.getFullYear().toString().slice(2);

*For earlier browsers "getFullYear" is not supported. To bad for them, sometimes the onus for usability is on the user. I know everyone will hate me for saying so but if you use some non-complient browser with cookies, graphics, javascript, external scripts and images disabled you should expect an incomplete internet experience.

Otherwise use:

theDate = new Date();
var lame = theDate.getYear();
if (lame < 2000) { lame += 1900 }
lame = lame.toString().slice(2);
document.write lame;