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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. JavaScript: How to convert string to date and Compare two dates.

JavaScript: How to convert string to date and Compare two dates.

Scheduled Pinned Locked Moved ASP.NET
javascripttutorial
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.
  • A Offline
    A Offline
    Abhishek Joshi
    wrote on last edited by
    #1

    JavaScript: How to convert string to date and Compare two dates. eg. If date1 is 08/18/06 and date2 is 08/19/06 Then it should give alert that "Date2 is greated than Date1:" :)

    P A 2 Replies Last reply
    0
    • A Abhishek Joshi

      JavaScript: How to convert string to date and Compare two dates. eg. If date1 is 08/18/06 and date2 is 08/19/06 Then it should give alert that "Date2 is greated than Date1:" :)

      P Offline
      P Offline
      playout
      wrote on last edited by
      #2

      It depends if you want to validate the dates on the aspx page, or in the code itself. The aspx method you can use a compare validator: You can have a look at the following link: http://www.sitepoint.com/article/asp-net-server-controls/8

      1 Reply Last reply
      0
      • A Abhishek Joshi

        JavaScript: How to convert string to date and Compare two dates. eg. If date1 is 08/18/06 and date2 is 08/19/06 Then it should give alert that "Date2 is greated than Date1:" :)

        A Offline
        A Offline
        ankushmn
        wrote on last edited by
        #3

        Check this out ... this will solve ur problem :) function CheckDate(oSrc,args) { args.IsValid=true; date1 = new Date(); date2 = new Date(); diff = new Date(); var objDOB = document.getElementById("txtHidDOB"); var AppDate = objDOB.value; if(AppDate != "") { var now = new Date(); var SysDate = parseInt(now.getMonth()+1)+"/"+now.getDate()+"/"+now.getFullYear() FromDateObj = new Date(AppDate + " " + "00:00:00"); date1.setTime(FromDateObj.getTime()); //alert(date1.getTime()) currDateObj = new Date(SysDate + " " + "00:00:00"); date2.setTime(currDateObj.getTime()); //alert(date2.getTime()) var DateDiff = date1.getTime() - date2.getTime(); //alert(DateDiff); if(DateDiff >= 0) { args.IsValid=false; } } }

        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