Is this Year a Leap Year? (using Shell Script Commands)
This page answers questions like these:
- How to find out if a year is a leap year?
- Is this year a leap year?
- Is a given year a leap year?
- Is a specific year a leap year?
Related Links:
What Day of the Week Was It?
Yesterday's Date using Shell Script Commands
Tomorrow's Date using Shell Script Commands
Is this Year a Leap Year?
if date -d "29 feb" >/dev/null 2>&1
then
echo "Yes, this year is a leap year."
else
echo "No, this year is a not leap year."
fi
- Tells you if the current year is/was a leap year or not.
- The -d option allows you to pass a string which alters the usual output value. Legal strings include (but are not limited too) "DD MMM" and "MMM DD".
- If you use a valid date, the return status will be zero and the date will be output to stdout.
- If you use an invalid date, the return status will be non-zero and an error message will be output to stderr.
- Caveats: Month names are locale-dependent.
Is a Given Year a Leap Year?
if date -d "29 feb YYYY" >/dev/null 2>&1
then
echo "Yes, YYYY is a leap year."
else
echo "No, YYYY is a not leap year."
fi
- Tells you if the year YYYY is/was a leap year or not.
- The -d option allows you to pass a string which alters the usual output value. Legal strings include (but are not limited too) "DD MMM" and "MMM DD".
- If you use a valid date, the return status will be zero. If you use an invalid date, the return status will be non-zero.
- Caveats: Month names are locale-dependent.
Related Links:
What Day of the Week Was It?
Yesterday's Date using Shell Script Commands
Tomorrow's Date using Shell Script Commands
Home > Linux / Unix > Is this Year a Leap Year? (using Shell Script Commands)
Tags: leap year, date, shell script, shell command, linux, unix, solaris, bsd, aix
Copyright © HelpDoco.com
date-leap-years.txt
Linux-Unix/is-this-year-a-leap-year-using-shell-script-commands.htm
2