LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Check for invalid date (https://www.linuxquestions.org/questions/programming-9/check-for-invalid-date-452558/)

Blackout_08 06-07-2006 06:27 PM

Check for invalid date
 
ok im trying to figure out how to determine if a date YYYYMMDD is invalid without checking if YYYY is greater than 0, MM is greater than 0 and less than 12, and DD is greater than 0 and less then 31/30/29/28. Any ideas?

graemef 06-07-2006 07:30 PM

Which language are you using? Some have builtin function to do that sort of work for you.

Blackout_08 06-07-2006 07:36 PM

/bin/bash is used

jim mcnamara 06-07-2006 08:28 PM

try
Code:

touch -t $DATE  dummy_file
if [ $? -ne 0 ] ; then
  echo "Invalid date"
fi

If you try to use an invalid date touch will return a non-zero value


All times are GMT -5. The time now is 02:06 PM.