Reputation: 341
To verify a valid date I use the command line below:
date -d "${DATE}" "+%Y/%m/%d" > /dev/null 2>&1
It works perfectly under Cygwin, but not in my test environment. Here's some information about my test environment:
uname -a
AIX 152101a07e 3 5 00CDE2314C00
Using the command line:
echo $?
The result is always 1, even if the date is valid.
Do you have any idea why this test fails?
Upvotes: 0
Views: 266
Reputation: 11866
Apparently, your two environments are not running the same version of date
. You should check the man
page for date
in your new environment (run man date
). On my machine (OS X), the -d
option is used for setting daylight savings time.
For example, the following works for me:
date -j -f "%Y/%m/%d" "2014/07/09" > /dev/null 2>&1
echo $? # 0
date -j -f "%Y/%m/%d" "2014.07.09" > /dev/null 2>&1
echo $? # 1
-j
tells it to not try to set my system date. -f
means to use the specified format.
Yours may be different, but you can find out the details by reading the manual.
Upvotes: 3