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. need Javascript to calculate day difference for dd-mm-yyyy hh:mm:ss(AM/PM)

need Javascript to calculate day difference for dd-mm-yyyy hh:mm:ss(AM/PM)

Scheduled Pinned Locked Moved JavaScript
javascriptdata-structuressalestoolshelp
2 Posts 2 Posters 8 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
    Alok Sharma ji
    wrote on last edited by
    #1

    hi i am using a javascript to calculate checkin checkout times of customer by using this script:

    function calculate()
    {
    if(window.formSugam.txtunitcost.value!="" && window.formSugam.txtquantity.value !=""){
    //-----------function for checking date and their validations
    var ONE_DAY = 1000 * 60 * 60 * 24;
    str1=new Array(6);
    str2=new Array(6);
    str1 = EnterDateInDDMMYY(window.formSugam.txtfromdate.value);
    // EnterDateInDDMMYY method is to convert date into miliseconds
    str2 = EnterDateInDDMMYY(window.formSugam.txttodate.value);
    var date1=new Date(str1[0],str1[1],str1[2],str1[3],str1[4],str1[5]);
    var date2=new Date(str2[0],str2[1],str2[2],str2[3],str2[4],str2[5]);
    var datediff=date2-date1;
    checkFloat(formSugam.txtunitcost)
    checknumbervalue(formSugam.txtquantity)
    val2=parseFloat(window.formSugam.txtunitcost.value );
    val1=parseInt(window.formSugam.txtquantity.value );
    dateval=parseInt(datediff);
    val3=parseInt(Math.round(dateval/ONE_DAY));
    if (val3==0)
    {window.formSugam.txtbillamount.value=val1*val2;}
    else{
    window.formSugam.txtbillamount.value=val1*val2*val3;
    }
    //----------------hence it calculates date in round figure
    }

    but the problem comes when i calculate a date diff for 31-10-2010 12:39:52PM to 01-11-2010 12:39:52PM else its working fine so what is the actual problem here in my code is related to month change,

    S 1 Reply Last reply
    0
    • A Alok Sharma ji

      hi i am using a javascript to calculate checkin checkout times of customer by using this script:

      function calculate()
      {
      if(window.formSugam.txtunitcost.value!="" && window.formSugam.txtquantity.value !=""){
      //-----------function for checking date and their validations
      var ONE_DAY = 1000 * 60 * 60 * 24;
      str1=new Array(6);
      str2=new Array(6);
      str1 = EnterDateInDDMMYY(window.formSugam.txtfromdate.value);
      // EnterDateInDDMMYY method is to convert date into miliseconds
      str2 = EnterDateInDDMMYY(window.formSugam.txttodate.value);
      var date1=new Date(str1[0],str1[1],str1[2],str1[3],str1[4],str1[5]);
      var date2=new Date(str2[0],str2[1],str2[2],str2[3],str2[4],str2[5]);
      var datediff=date2-date1;
      checkFloat(formSugam.txtunitcost)
      checknumbervalue(formSugam.txtquantity)
      val2=parseFloat(window.formSugam.txtunitcost.value );
      val1=parseInt(window.formSugam.txtquantity.value );
      dateval=parseInt(datediff);
      val3=parseInt(Math.round(dateval/ONE_DAY));
      if (val3==0)
      {window.formSugam.txtbillamount.value=val1*val2;}
      else{
      window.formSugam.txtbillamount.value=val1*val2*val3;
      }
      //----------------hence it calculates date in round figure
      }

      but the problem comes when i calculate a date diff for 31-10-2010 12:39:52PM to 01-11-2010 12:39:52PM else its working fine so what is the actual problem here in my code is related to month change,

      S Offline
      S Offline
      Sunasara Imdadhusen
      wrote on last edited by
      #2

      Please visit following link http://stackoverflow.com/questions/1036742/date-difference-in-javascript-ignoring-time-of-day[^] Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose: Thanks, Imdadhusen

      sunaSaRa Imdadhusen +91 99095 44184 +91 02767 284464

      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