Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
3 つの列を持つデータベースがあり、すべて VARCHAR(20)
dob_day dob_month dob_year
これらをPHPの日付/タイムスタンプに変換して、人の年齢(行)を取得するにはどうすればよいですか
たとえば、次のものがあったとします。
dob_day = 07 dob_month = 08 dob_year = 1994
ユーザーは 19 歳になるため、これは 19 を表示する必要があります。
生年月日を として保存する必要がありますdate。このソリューションは、データベース側から年齢を返します。
date
SELECT TIMESTAMPDIFF(YEAR,CONCAT(dob_year, '-', dob_month, '-', dob_day),CURDATE()) AS `age`
結果
| | 年齢 | ------- | | 19 |
デモを見る