SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Two Digit Year?

  1. #1
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Two Digit Year?

    I am using the following Javascript to print the year, but I would like it to just have "03" instead of "2003". Can somebody tell me how to do this? I've tried searching several different sites and I can't figure out how to do this.

    document.write(now.getFullYear());
    John Saunders

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

    Re: Two Digit Year?

    Try this?
    Code:
    var now = new Date()
    var theYear = now.getFullYear(); 
    var last2Digits = theYear.substring(0, 2);
    document.write(last2Digits);

  3. #3
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about:

    Code:
    var oDate = new Date();
    var sDate = new String(oDate.getFullYear());
    document.write(sDate.substr(2));

  4. #4
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys!
    John Saunders

  5. #5
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ooops, didn't see vgarcia's response before my post..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •