Fairly simple and I’m sure this would come in handy in the future. This is one of those functions that I thought did not exist. I should RTFM more…
SELECT DATEDIFF('2009-03-31 23:59:59','2009-03-29'); /*would output: 2*/ /*Another usage would be something like: */ SELECT p.* FROM people p WHERE p.country LIKE 'Phil%' AND DATEDIFF(p.travel_date_to,p.travel_date_from)>=15 /* In this scenario, the query would give me a list of people who are on vacation in the Philippines for more than 15 days. I used the travel_date_to and travel_date_from fields. */ /* How many days old am I? */ SELECT DATEDIFF(curdate(), '1983-10-29' ); /* would output 9281 days :P */ |