Common MySQL Queries

I ran across this terrific resource, Common MySQL Queries .

Tons of great examples…for example:

Given a birthdate in @dob, here are two simple formulae for age in years:

Date_format( From_Days( To_Days(Curdate()) - To_Days(@dob) ), '%Y' ) + 0
Year(Curdate()) - Year(@dob) - ( Right(Curdate(),5) < Right(@dob,5) )

and here is one for age in years to two decimal places, ignoring day of month:

Round((((Year(now()) - Year(@dob)))*12 + (((Month(now()) - Month(@dob)))))/12, 2)

Enjoy!

Tags :

Related Posts

Double Basket Beanie Pattern Is Live

Double Basket Beanie Pattern Is Live

I finally finished writing the pattern to my satisfaction and testing the various options.

Read More
My Favorite Everything Socks

My Favorite Everything Socks

My first package from the wonderful Woolens & Nosh yarn club was from October, 2023, and since it was my first, I wanted to make something special with it.

Read More
Double Basket Beanie Prototype

Double Basket Beanie Prototype

I finished the first prototype of my new Double Basket Beanie.

Read More