title: Google Sheet converting wrong the date
body: <p>I vave a column that i only write numbers in the cells. Like for example:
  I write <code>15022019</code> then i go to number formats and choose <code>date</code>. So the number is converted to <code>15/02/2019</code>. 
  But i don't need everytime when i write a number make the change to date format. I need it automatically. So i found this script:</p>
  
  <pre><code>var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0]; 
  var column = sheet.getRange("D3:D31"); 
  column.setNumberFormat("dd/mm/yyy");
  </code></pre>
  
  <p>It work. But is changing the numbers to date format incorrectly. If i write <code>14022019</code> its convert to  <code>24/12/40290</code>, and not in <code>14/02/2019</code>(how i expected).
  Why that?
  Just in manually way it converts rightly. My location is Brazil.</p>
  
  <p>Can someone say me what i'm doing wrong?</p>
  
  <hr>
  
  <p><strong>Edit 1:</strong></p>
  
  <p>I need it to convert to date automatically each time i fill a cell with the date. My range date will be always <code>D3:D31</code>. I tried modify the lines bellow:</p>
  
  <pre><code>function convertnumbertodate(crange){
  
    // establish spreadsheet credentials
    var ss1=SpreadsheetApp.getActive();
    var sh1=ss1.getActiveSheet();
  
    // get the range so that rows and columns can be calculated
    var rg1=sh1.getRange(crange);
  </code></pre>
  
  <p>And in the place of <code>(crange)</code> i put <code>D3:D31</code> to try to make the conversion to date automatically. Look bellow:</p>
  
  <pre><code>function convertnumbertodate(crange){
  
    // establish spreadsheet credentials
    var ss1=SpreadsheetApp.getActive();
    var sh1=ss1.getActiveSheet();
  
    // get the range so that rows and columns can be calculated
    var rg1=sh1.getRange(D3:D31);
  </code></pre>
  
  <p>But when i run the function <code>convertnumbertodate</code> it reports error.
  Can you help me how make it convert to date automatically?</p>
  
  <p>Thank you</p>
  
  <hr>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>Just made what you did:</p>
  
  <pre><code>    function convertnumbertodate() {
  
        // establish spreadsheet credentials
        var editedCell;
        var sh1=ss1.getActiveSheet();
  
        // get the range so that rows and columns can be calculated
        var rg1=sh1.getRange(D3:D31);
  
        // get number of columns
        var numColumns = rg1.getNumColumns();
  
        // if more than one column chosen, stop the process. 
        if (numColumns !=1){
          //Logger.log("DEBUG: Number of columns in range = "+numColumns); // DEBUG
          var message = "Too Many Columns; one column only";
          return message;
        }
  etc.
  </code></pre>
  
  <p>I deleted the <code>crange</code> and put my range <code>D3:D31</code>
  Also made it run <code>OnEdit</code>: <code>var editedCell;</code></p>
  
  <p>But when i run, it says thats have an error in the line <code>var rg1=sh1.getRange(D3:D31);</code></p>