Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple "Where" Clause for "DateTime" comparison

Tags:

datetime

mysql

I am trying to see whether a Person was older than a certain age at a specific point in time.

So currently specificTime is a DATETIME attritube and it has a value of '2011-05-21'

The Age is also a DATETIME attribute.

Does anyone have any ideas to a query that will determine whether the Age of a person is greater than 15 years old at the specificTime

like image 976
User1204501 Avatar asked May 14 '26 13:05

User1204501


1 Answers

try

select * from Person where (datediff(specificTime,Age) / 365) > 15

For more details on datetime functions refer http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_datediff

like image 193
Krishna Rani Sahoo Avatar answered May 16 '26 01:05

Krishna Rani Sahoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!