title: Google Form asks for duration, how to calculate with this in Google App Script
body: <p>I use stackoverflow on a regular basis to find answers to my problems, but I cannot seem to solve this one. So here is my first question:</p>
  
  <p>I have a Google form that (amongst other things) asks for the duration of a job. I want the google spreadsheet to contain the form-answers, and add some columns. In this case, I want to add the cost of the job, using an hour rate of 126,-</p>
  
  <p>But I keep running into problems in calculating with the duration: my script either tells me its a text (if I use getDisplayValue in retrieving the data), or it gives me a #NUM error in the spreadsheet itself.</p>
  
  <p>Can anyone pinpoint me towards a solution how to retrieve the hours and the minutes from the form-field (time as duration), so I can do some basic math with it in the script?</p>
  
  <p>I've setup a small form and connected spreadsheet showing my problems. The example form only asks for the duration, and places this in the spreadsheet in column 2. In the spreadsheet I've setup a script that runs on form submit an I try to explain all steps I do. The script should take the form input, convert it to hours (as a num-field) and multiply that with the PricePerHour. The result should be placed in column 3 on the same row of the form submit.</p>
  
  <p>This is my script so far:</p>
  
  <pre><code>// CALCULATE COST OF JOB
  function calculatePriceDuration(e) {
  
    // get source data
    var sourceSheet          = SpreadsheetApp.getActiveSheet();                                            // connect to source sheet
    var sourceRow            = sourceSheet.getActiveRange().getRow();                                      // connect to event row (form submit)
  
  
    // get destination data
    var destinationSheet    = sourceSheet;                                                                 // connect to destination sheet
    var destinationRow      = sourceRow;                                                                   // connect to destination row
    var destinationColID    = 3;                                                                           // set column number of value to paste
  
  
    // set variables
    var colID_FormDuration   = 2;                                                                          // set column number where the form places the duration
    var formDuration         = sourceSheet.getRange(sourceRow, colID_FormDuration).getDisplayValue();      // get value for duration 
  
  
    // set price per hour 
    var PricePerHour         = 126;
  
    // calculate job price
    var PriceForJob          = formDuration * PricePerHour;
  
    // set destination cell
    destinationSheet.getRange(destinationRow,destinationColID).setValue(PriceForJob);                      // paste value in the 3rd column of the same row of form submit
  
  }
  </code></pre>
  
  <p>the spreadsheet itself can be found <a href="https://docs.google.com/spreadsheets/d/1jnLmIyjA15ll1bxEyQvJpMFVvC-qPpTR9202mJwyx1Y/edit#gid=480868069" rel="nofollow noreferrer">here</a>:</p>
  
  <p>the form can be found <a href="https://docs.google.com/forms/d/e/1FAIpQLSdniHbIK13G2YXY3TcCjxSqXZ5vxDZl6aEID7wEJqi9QrVajQ/viewform" rel="nofollow noreferrer">here</a>: </p>
  
  <p>Any help is much appreciated!
  Kind regards,
  Rob</p>