次の誕生日計算機
次の誕生日までの日数、現在の年齢、曜日を計算します。
このツールについて
誕生日は毎年祝う大切な日ですが、次の誕生日までの正確な日数を把握することは、特別なお祝いの計画立てや大切な人への連絡、あるいは単に次のお祝いがどのくらい先か知りたいときに驚くほど役立ちます。このNext Birthday Calculatorは、生年月日に基づいて次の誕生日までの残り日数を即座に計算し、現在の年齢を表示し、さらに次の誕生日がどの曜日に当たるかも教えてくれます。
このツールの使い方は非常にシンプルです。生年月日を入力するだけで、カウントダウンの日数、正確な年齢(年単位)、そして次の誕生日の曜日名がすぐに表示されます。誕生日がいつであっても、数ヶ月先でも数週間先でも対応でき、サプライズパーティの計画立てや誕生日関連のイベント予定、事前通知の設定に最適です。
よくある質問
コード実装
from datetime import date
def next_birthday_info(birth_date: date, today: date = None) -> dict:
"""Calculate days until next birthday, current age, and day of week."""
if today is None:
today = date.today()
age = today.year - birth_date.year
# Check if birthday already happened this year
had_birthday = (today.month, today.day) >= (birth_date.month, birth_date.day)
if not had_birthday:
age -= 1
# Next birthday
next_year = today.year if not had_birthday else today.year + 1
try:
next_bday = date(next_year, birth_date.month, birth_date.day)
except ValueError: # Feb 29 on non-leap year
next_bday = date(next_year, 3, 1)
days_until = (next_bday - today).days
day_of_week = next_bday.strftime("%A")
return {
"current_age": age,
"next_birthday": next_bday.isoformat(),
"days_until": days_until,
"day_of_week": day_of_week,
"is_today": days_until == 0,
}
info = next_birthday_info(date(1990, 7, 15))
print(f"Age: {info['current_age']}")
print(f"Next birthday: {info['next_birthday']} ({info['day_of_week']})")
print(f"Days until: {info['days_until']}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.