title: Formatting date to yyyy-mm-dd in cell
body: <p>In [excel-vba], I am trying to format the text from a UserForm textbox, format it to yyyy-mm-dd and input it into a cell  with the following code:</p>
  
  <pre><code>Private Sub GenerateButton_Click()
      Worksheets("Sheet1").Activate
  
      Sheet1.Unprotect
      Dim startTime, endTime, startDate
      startTime = t_daylasthour.Text
      endTime = t_daylasthour.Text
      startDate = t_startdate.Value
  
      Dim counter As Integer
      counter = 1
  
      Do
          Set field = ActiveWorkbook.Sheets("Sheet1").Cells(counter + 1, 1)
          field.Value = Format(t_startdate.Text, "yyyy-mm-dd") 
          counter = counter + 1
      Loop While counter &lt; 10
  
  End Sub
  </code></pre>
  
  <p>The output in the cell keeps coming out in the form yyyy/mm/dd. Any other format that I try in my code appears to work. I tried yyyy - mm - dd for example, and it work, but everytime I try the format listed in the code above, it doesn't.</p>
  
  <p>Any ideas on what I'm doing wrong?</p>