title: MySQL get date of last month
body: <p>I have this script which is run on the 15th of every month. This script intends to automatically take the last date of the previous month in the format of 'YYYY-MM-DD'. Is there a sql statement to do that?</p>
  
  <p>For example today is 15th January 2017. I will run my script and it will give me a date of 31th December 2016 in the format 2016-12-31.</p>
  
  <p>If it is 15th December 2016, I will get 30th November 2016 in the format 2016-11-30. </p>
  
  <p>Thank you  </p>