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. comparing two dates in javascript

comparing two dates in javascript

Scheduled Pinned Locked Moved JavaScript
javascript
4 Posts 4 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.
  • M Offline
    M Offline
    Member 10263519
    wrote on last edited by
    #1

    i want to compare dates . startjourney=moment(moment($('#onDate').val()).format("DD/MM/YYYY")+' '+ $('#starttime').val(),"DD/MM/YYYY h:mm A");//concate date and time am getting 27/01/2016 12:00 AM newDate=moment(startjourney).add(mapDuration[0],'days').add(mapDuration[2],'hours').add(mapDuration[4],'minutes').format("DD/MM/YYYY hh:mm A");//29/01/2016 10:17 AM // returnJourneyDate=newDate.split(" ")[0]; // // endTime=moment(newDate.split(" ")[1]+ ' '+newDate.split(" ")[2],"h:mm A "); // selectedTime=moment($('#starttime').val(),"h:mm A"); alert(moment($('#returntime').val(),"HH:MM").toDate()); selectedjourney=moment($('#returndate').val()+' '+ moment($('#returntime').val(),"HH:MM")).toDate();//concate date and time as strings selectedDate=moment(selectedjourney,"DD/MM/YYYY h:mm A").toDate(); var date=new Date(selectedjourney,"DD/MM/YYYY hh:mm tt"); var d=moment( $('#returntime').val(),"HH:MM").toDate(); var h=new Date(selectedDate); if(selectedjourney.isBefore(newDate))// test selected one is before newDate bootbox.alert( "Return journey time must be after " + newDate);

    L Richard DeemingR B 3 Replies Last reply
    0
    • M Member 10263519

      i want to compare dates . startjourney=moment(moment($('#onDate').val()).format("DD/MM/YYYY")+' '+ $('#starttime').val(),"DD/MM/YYYY h:mm A");//concate date and time am getting 27/01/2016 12:00 AM newDate=moment(startjourney).add(mapDuration[0],'days').add(mapDuration[2],'hours').add(mapDuration[4],'minutes').format("DD/MM/YYYY hh:mm A");//29/01/2016 10:17 AM // returnJourneyDate=newDate.split(" ")[0]; // // endTime=moment(newDate.split(" ")[1]+ ' '+newDate.split(" ")[2],"h:mm A "); // selectedTime=moment($('#starttime').val(),"h:mm A"); alert(moment($('#returntime').val(),"HH:MM").toDate()); selectedjourney=moment($('#returndate').val()+' '+ moment($('#returntime').val(),"HH:MM")).toDate();//concate date and time as strings selectedDate=moment(selectedjourney,"DD/MM/YYYY h:mm A").toDate(); var date=new Date(selectedjourney,"DD/MM/YYYY hh:mm tt"); var d=moment( $('#returntime').val(),"HH:MM").toDate(); var h=new Date(selectedDate); if(selectedjourney.isBefore(newDate))// test selected one is before newDate bootbox.alert( "Return journey time must be after " + newDate);

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      This is very similar to your QA issue at add hh:mm to hh:mm to get new hh:mm then return new date[^]. What exactly is the problem?

      1 Reply Last reply
      0
      • M Member 10263519

        i want to compare dates . startjourney=moment(moment($('#onDate').val()).format("DD/MM/YYYY")+' '+ $('#starttime').val(),"DD/MM/YYYY h:mm A");//concate date and time am getting 27/01/2016 12:00 AM newDate=moment(startjourney).add(mapDuration[0],'days').add(mapDuration[2],'hours').add(mapDuration[4],'minutes').format("DD/MM/YYYY hh:mm A");//29/01/2016 10:17 AM // returnJourneyDate=newDate.split(" ")[0]; // // endTime=moment(newDate.split(" ")[1]+ ' '+newDate.split(" ")[2],"h:mm A "); // selectedTime=moment($('#starttime').val(),"h:mm A"); alert(moment($('#returntime').val(),"HH:MM").toDate()); selectedjourney=moment($('#returndate').val()+' '+ moment($('#returntime').val(),"HH:MM")).toDate();//concate date and time as strings selectedDate=moment(selectedjourney,"DD/MM/YYYY h:mm A").toDate(); var date=new Date(selectedjourney,"DD/MM/YYYY hh:mm tt"); var d=moment( $('#returntime').val(),"HH:MM").toDate(); var h=new Date(selectedDate); if(selectedjourney.isBefore(newDate))// test selected one is before newDate bootbox.alert( "Return journey time must be after " + newDate);

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        You seem to have forgotten to ask a question. You've told us what you want to do; you've shown us the code you've got; but you haven't told us what the problem is. If you're getting an error, post the full details of the error, and tell us which line of code it's thrown from. If it's not doing what you want, tell us what the inputs are, and describe what it's actually doing.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        • M Member 10263519

          i want to compare dates . startjourney=moment(moment($('#onDate').val()).format("DD/MM/YYYY")+' '+ $('#starttime').val(),"DD/MM/YYYY h:mm A");//concate date and time am getting 27/01/2016 12:00 AM newDate=moment(startjourney).add(mapDuration[0],'days').add(mapDuration[2],'hours').add(mapDuration[4],'minutes').format("DD/MM/YYYY hh:mm A");//29/01/2016 10:17 AM // returnJourneyDate=newDate.split(" ")[0]; // // endTime=moment(newDate.split(" ")[1]+ ' '+newDate.split(" ")[2],"h:mm A "); // selectedTime=moment($('#starttime').val(),"h:mm A"); alert(moment($('#returntime').val(),"HH:MM").toDate()); selectedjourney=moment($('#returndate').val()+' '+ moment($('#returntime').val(),"HH:MM")).toDate();//concate date and time as strings selectedDate=moment(selectedjourney,"DD/MM/YYYY h:mm A").toDate(); var date=new Date(selectedjourney,"DD/MM/YYYY hh:mm tt"); var d=moment( $('#returntime').val(),"HH:MM").toDate(); var h=new Date(selectedDate); if(selectedjourney.isBefore(newDate))// test selected one is before newDate bootbox.alert( "Return journey time must be after " + newDate);

          B Offline
          B Offline
          Beginner Luck
          wrote on last edited by
          #4

          Is this what you want?? [Demo] Date Comparision in JavaScript - JSFiddle[^]

          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