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

Research Guide: Knitting History and Techniques

Research Guide: Knitting History and Techniques

For a recent class, I needed to create a beginner research guide for a topic that interests me.

Read More
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