Validate date format in a shell script

后端 未结 12 1800
我在风中等你
我在风中等你 2020-11-29 11:11

I have to create a Shell Script wherein one of the parameters will be the date in the format dd/mm/yyyy. My question is, how can I check if the Date passed as parameter real

12条回答
  •  清歌不尽
    2020-11-29 11:47

    Use date

    date "+%d/%m/%Y" -d "09/99/2013" > /dev/null  2>&1
     is_valid=$?
    

    If you do not get 0 then date is in invalid format.

提交回复
热议问题