title: Bash validate date
body: <p>I'm writing a shell script and am confused as to why my date validation code is not working. I tried the following solutions to similar questions I found, but is_valid is always set to 1:</p>
  
  <pre><code>date "+%m/%d/%Y" -d "$1" 2&gt;1 &gt; /dev/null
  //or..
  date -d "2012-02-29" &gt; /dev/null 2&gt;&amp;1
  is_valid=$?
  #always set to 1, even when given a valid date
  </code></pre>
  
  <p>How do I correctly validate the date format? The date should only be valid if in the format MM/DD/YYYY</p>
  
  <p>I also tried this solution: <a href="https://stackoverflow.com/questions/14152759/linux-bash-date-format">Linux Bash - Date Format</a> but it always rejected the date as well.</p>