If you are not selecting NULL
or empty
entries from the date columns, then
drop table if exists x;
create table x
select
cast( date_format( BIRTH_DT,'%Y-%m-%d' ) as date ) as BIRTH_DT
, cast( date_format( TERMINATION_DT,'%Y-%m-%d' ) as date ) as Term_Date
, cast( round( datediff( date_format( TERMINATION_DT, '%Y-%m-%d' ),
date_format( BIRTH_DT, '%Y-%m-%d' )
) / 365, 0 ) as decimal( 6, 2 ) ) as Age
from dashboard_04102014
where
status = 'withdrawn'
-- un comment following line if required
-- AND ( BIRTH_DT is not null and BIRTH_DT = '' and BIRTH != 0 )
and ( TERMINATION_DT is not null
and TERMINATION_DT != ''
and TERMINATION_DT != 0 )
;
Result:
desc x;
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| BIRTH_DT | date | YES | | NULL | |
| Term_Date | date | YES | | NULL | |
| Age | decimal(6,2) | YES | | NULL | |
+-----------+--------------+------+-----+---------+-------+
select * from x;
+------------+------------+-------+
| BIRTH_DT | Term_Date | Age |
+------------+------------+-------+
| 1992-07-31 | 2050-07-31 | 58.00 |
| 1971-02-24 | 2029-02-24 | 58.00 |
+------------+------------+-------+
Demo 1 @ MySQL 5.5.32 Fiddle
Demo 2 @ MySQL 5.5.32 Fiddle