MySQL - DATA TYPES for time/date
Useful Functions - ALL the time & date functions may come in handy... some day
MySQL - Date & Time Fcn's
-and-
MySQL - Temporal Intervals
Dr. Dale's....set of go to functions is FAR more LIMITED
now()
current_date
interval.... (ie, interval 1 day)
timestampdiff ( unit, leftOperand, rightOperand )
ie, timestampdiff( day , DOB, NOW() )
#-------------------------------------------------------------
# diff ... aka ... difference as in
#
# THE DIFFERENCE BETWEEN TWO DATES,
# for example
# date of birth -AND- this minute
# Should this be measured in.... days? months? years? what?
#-------------------------------------------------------------
#-- units now-dob = Age, (-:
select *, TIMESTAMPDIFF( DAY, DOB, NOW() ) as 'Age (days)'
, TIMESTAMPDIFF( MONTH, DOB, NOW() ) as 'Age (mos)'
, TIMESTAMPDIFF( YEAR, DOB, NOW() ) as 'Age (yrs)'
from pet;
All pets born in the last six years?
select * from pet WHERE pet.DOB > now() - interval 6 year;
What if ... well, they're no longer living?
# LIVING pets born in the last six years?
select * from pet WHERE pet.DOB > now() - interval 6 year
AND DOD is NULL;
### DON'T USE =NULL Why not?
The result of any arithmetic comparison with NULL is also NULL,
so....you cannot obtain any meaningful results from such comparisons.
### DON'T use ==NULL Why not?
No such operator in MySQL; Bad Syntax