title: Changing date format in R to subtract dates
body: <p>I'm trying to subtract one date from another and then write the output in terms of the number of days. The problem is that the two dates I have are formatted differently -- I've tried to change the formatting, but it doesn't work.</p>
  
  <p>In <code>df2$Filedate</code>, dates are formatted as <code>%Y-%m-%d</code>, e.g. <code>2015-01-03</code>.
  In the other column containing dates, <code>df2$Date</code>, the formatting is <code>%y-%m-%d</code>, e.g. <code>15-01-01</code>.</p>
  
  <p>So if I can convert <code>df2$Filedate</code> from <code>%Y-%m-%d</code> to <code>%y-%m-%d</code>, I should be able to subtract dates and write to a new column like this:</p>
  
  <pre><code>df2$z &lt;- df2$Filedate - df2$Date
  </code></pre>
  
  <p>This is what I've tried. First, I format:</p>
  
  <pre><code>df2$Filedate &lt;- format(df2$Filedate, "%y-%m-%d")
  </code></pre>
  
  <p>The output now looks correct. I convert these strings to dates again, like this:</p>
  
  <pre><code>df2$Filedate &lt;- as.Date(df2$Filedate, "%y-%m-%d")
  </code></pre>
  
  <p>And the dates are now, again, formatted as <code>%Y-%m-%d</code>!</p>