title: Accept date as user input in bash script
body: <p>I want to accept date as input in <code>dd-mm-yyyy</code> format as user input (via read) and then convert it as a date object in shell script. How can I achieve this.
  I have had success with <code>yyyy-mm-dd</code> but somehow,it is not working for my use case.</p>
  
  <p>This is my script:-</p>
  
  <pre><code>#!/bin/bash
  read -p "Enter a date (dd-mm-yyyy): " user_date
  if date=$(date -d "$user_date" +'+%d-%m-%Y'); then 
    # user date was ok
    echo $date
  </code></pre>
  
  <p>This is my input:-</p>
  
  <pre><code>./2.sh
  Enter a date (dd-mm-yyyy): 11-1-2011
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>date: invalid date `11-1-2011'
  </code></pre>
  
  <p>Thanks</p>