Skip to content

Instantly share code, notes, and snippets.

@KimiyukiYamauchi
Created June 12, 2018 06:04
Show Gist options
  • Save KimiyukiYamauchi/750d5c7073bbd7bfb0a259e447923826 to your computer and use it in GitHub Desktop.
Save KimiyukiYamauchi/750d5c7073bbd7bfb0a259e447923826 to your computer and use it in GitHub Desktop.
#!/bin/bash
thisyear=$(date '+%Y') # 今年の年
birthday=$(date -d "${thisyear}${1}" '+%s') # 今年の誕生日のエポック
today=$(date '+%s') # 本日のエポック
if [ "$birthday" -gt "$today" ]; then
echo $(((birthday - today) / (60*60*24) + 1))
elif [ $(date '+%m%d') = "${1}" ]; then
echo 'Today is birthday.'
else
nextbirthday=$(date -d "${thisyear}${1} next year" '+%s') # 来年の誕生日のエポック
echo $(((nextbirthday - today) / (60*60*24) + 1))
fi
@KimiyukiYamauchi
Copy link
Author

./bd.sh mmdd
ex)
./bd.sh 0313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment