MysqlMysql

  Main Menu

Home: Development: Mysql: Birthday_countdown

Problem:
Determine age and countdown to birthday from a given date.
Here is a simple query to find age in days from a mysql style date, using mysql's builtin TO_DAYS function:

  mysql> select (to_days(now()) - to_days( bday)) / 365 
  as age_in_days from fam;

Here is the line to get the countdown to bday using mysql's builtin TO_DAYS function:

  mysql> select dayofyear(bday) - dayofyear(now()) as count_down from fam;

Based of course on having this table, with valid birthday (bday) dates in it:

  create table fam (
    id int unsigned primary key auto_increment not null,
    f_name varchar(255),
    l_name varchar(255),
    address varchar(255),
    city varchar(255),
    state varchar(255),
    zip varchar(255),
    h_phone varchar(255),
    m_phone varchar(255),
    f_phone varchar(255),
    email varchar(255),
    bday date
  );