Generate random birth date in MySQL table and get Age by select


Today I was solving generating of random data for testing and manipulation with the date of the birth. <br> <br>Here are two simple SQL queries solving both:

Query for generate random date of birth in whole table

Update for all inside table_name order by id for example:
UPDATE 
database_name
SET
table_name=CONCAT_WS('-',(FLOOR( 1940 + RAND( ) *100)),(FLOOR( 1 + RAND( ) *12 )),(FLOOR( 1 + RAND( ) *28 )))
ORDER BY user_id

Query for selecting date of birth and calculation of age in MySQL:

SELECT 
table_name_date_of_birth,DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(date_of_birth, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') DATE_FORMAT(date_of_birth, '00-%m-%d')) AS age
FROM database_name
411 Views