Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Javascript and Dates

Javascript and Dates

Scheduled Pinned Locked Moved JavaScript
questionjavascripttutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BobInNJ
    wrote on last edited by
    #1

    I have a string in the form of d+/d+/d+. For example, the string might be 1/1/2011. This string would represent the date January 1, 2011. This application uses a banker's year. That means 30 days for each and every month and 360 days to the year. Now, if I have this string in a variable d1 what is the best way to extract the year, month and day? Thanks Bob

    D M 2 Replies Last reply
    0
    • B BobInNJ

      I have a string in the form of d+/d+/d+. For example, the string might be 1/1/2011. This string would represent the date January 1, 2011. This application uses a banker's year. That means 30 days for each and every month and 360 days to the year. Now, if I have this string in a variable d1 what is the best way to extract the year, month and day? Thanks Bob

      D Offline
      D Offline
      Dennis E White
      wrote on last edited by
      #2

      var date='1/1/2011';
      var parseDate = date.split('/');

      document.write('year - ' + parseDate[2] + '
      ');
      document.write('month - ' + parseDate[1] + '
      ');
      document.write('day - ' + parseDate [0] + '
      ');

      as if the facebook, twitter and message boards weren't enough - blogged

      1 Reply Last reply
      0
      • B BobInNJ

        I have a string in the form of d+/d+/d+. For example, the string might be 1/1/2011. This string would represent the date January 1, 2011. This application uses a banker's year. That means 30 days for each and every month and 360 days to the year. Now, if I have this string in a variable d1 what is the best way to extract the year, month and day? Thanks Bob

        M Offline
        M Offline
        Morgs Morgan
        wrote on last edited by
        #3

        You can use the more accurare way,

        var date = new Date(d1);

        //get your date components like so:
        var day = date.getDay();
        var month = date.getMonth();
        var year = date.getYear();

        See link here: - http://www.w3schools.com/js/js_obj_date.asp[^] Happy coding, Morgs

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups