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. How to Know The Selected Date is Previous in javascript

How to Know The Selected Date is Previous in javascript

Scheduled Pinned Locked Moved JavaScript
javascripthelptutorialquestion
3 Posts 3 Posters 2 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.
  • A Offline
    A Offline
    Arunkumar Koloth
    wrote on last edited by
    #1

    Hi all Iam New to javascript can you help me how to check the selected date is previous one? eg:today is 14/8/2011 and i selected 12/8/2011 in a javascript calender i want to validate the selected date is previus one is it possible? Please Help me Arunkumar.T :((

    D N 2 Replies Last reply
    0
    • A Arunkumar Koloth

      Hi all Iam New to javascript can you help me how to check the selected date is previous one? eg:today is 14/8/2011 and i selected 12/8/2011 in a javascript calender i want to validate the selected date is previus one is it possible? Please Help me Arunkumar.T :((

      D Offline
      D Offline
      DaveAuld
      wrote on last edited by
      #2

      Do you mean you want to make sure the selected date is BEFORE todays date? If thats all you need then a simple DateDiff and look for a +ve or -ve number depending on whether you put the latestdate first or second; http://ditio.net/2010/05/02/javascript-date-difference-calculation/[^]

      Dave Find Me On: Web|Facebook|Twitter|LinkedIn


      Folding Stats: Team CodeProject

      1 Reply Last reply
      0
      • A Arunkumar Koloth

        Hi all Iam New to javascript can you help me how to check the selected date is previous one? eg:today is 14/8/2011 and i selected 12/8/2011 in a javascript calender i want to validate the selected date is previus one is it possible? Please Help me Arunkumar.T :((

        N Offline
        N Offline
        Niral Soni
        wrote on last edited by
        #3

        /************************************************
        function: CompareDates
        Arguments: fromdate : type 'String' : format : DD/MM/YYYY
        Arguments: todate : type 'String' : format : DD/MM/YYYY
        Returns: Number value
        if value = 1 : fromdate comes before todate
        if value = 0 : fromdate and todate are same
        if value = -1 : fromdate comes after todate
        *************************************************/
        function CompareDates(fromdate,todate) {
        // Assuming the date format = DD/MM/YYYY
        // modify following block if your date format is different
        // new Date(year,month,day)
        frmdt = new Date(fromdate.substring(6,10),fromdate.substring(3,5)-1,fromdate.substring(0,2));
        todt = new Date(todate.substring(6,10),todate.substring(3,5)-1,todate.substring(0,2));

        if ( todt.getTime() > frmdt.getTime() ) {
        	return 1;
        }
        else if( todt.getTime() == frmdt.getTime() ) {
        	return 0;
        }
        return -1;
        

        }

        Thanks & Regards, Niral Soni

        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