metalx1000

BASH validate date format

May 15th, 2021
960
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. read -p "What is the date of the event? " d
  4.  
  5. date -d "$d" -I > /dev/null|| exit 1
  6. date="$(date -d "$d" +%m/%d/%Y)"
  7. day="$(date -d "$d" +%A)"
  8.  
  9. echo "You Selected $date"
  10. echo "and $day was the day of the week"
  11.  
RAW Paste Data