mysql

MYSQL Date Comparison Cheat Sheet

Below are some methods of comparing dates in MYSQL.

Finding rows entered in the last 6 months with MYSQL.

SELECT *
FROM table_name
WHERE post_date > DATE_SUB(GETDATE(), INTERVAL 6 MONTH)

Finding the number of days between two dates

SELECT  DATEDIFF(end_date ,start_date)
FROM table_name;

Finding the midpoint or average between to dates.

SELECT (start_date+INTERVAL DATEDIFF(end_date ,start_date)/2 DAY)
FROM table_name;

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.