commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Quick and easy way of validating a date format of yyyy-mm-dd and returning a boolean, the regex can easily be upgraded to handle "in betweens" for mm dd or to validate other types of strings, ex. ip address.
Boolean output could easily be piped into a condition for a more complete one-liner.
There are 8 alternatives - vote for the best!
On CentOS at least, date returns a boolean for the common date string formats, including YYYY-MM-DD. In the sample output, you can see various invalid dates returning 0 whereas a simple regex check would return 1 for the invalid dates.
-d, --date=STRING display time described by STRING, not `now'
The version of date on OS X does not appear to have this same option.
If you can do better, submit your command here.
You must be signed in to comment.