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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date format problem

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I use getYear() to get the year '2001'.
As I want to present as dd/mm/yy, I used substring to extract the '01', but failed.
here's my code:
to_date = new Date();
year = to_date.getYear();
year = year.substring(2,4); //<-- error here

so should I convert year to string format first?
and how?
 
hi, you can solve the problem doing this:

var d_date = new Date(); // lock de system date
d_date = d_date.getYear(); // Get the year
d_date = d_date.toString(); // Convert the variable to string
d_date = d_date.substr(2,2); // Substrack the 2 end numbers

//d_date now have the value 01

Best Regard's
Vegeta
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top