Results 1 to 3 of 3

Thread: Get year in two digits?

  1. #1
    Junior Registered
    Join Date
    Nov 2003
    Location
    EarthPlanet
    Posts
    2

    Get year in two digits?

    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 ?

  2. #2
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    You don't want this bug to resurface again. Use 4 digit years.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  3. #3
    Collarbeam
    Join Date
    Sep 2006
    Location
    Toronto
    Posts
    3

    Exclamation Getting a year with the last two digits:

    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;

Similar Threads

  1. Replies: 0
    Last Post: 05-15-2004, 03:29 PM
  2. New Year Specials - Shared & Reseller Hosting
    By bjdea1 in forum The Marketplace
    Replies: 0
    Last Post: 01-02-2004, 09:29 PM
  3. Happy New Year Everybody
    By wrigh_g in forum General Chat
    Replies: 1
    Last Post: 01-01-2004, 03:07 PM

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
  •