MySQL Match Dates with a UNIXTIME Field

December 19th, 2008 | Posted in MySQL
1

Here is how to grab and compare a date directly from a MySQL query if you are storing your dates as UNIXTIME.

SELECT
	*
FROM
	table
WHERE
	MONTH(FROM_UNIXTIME(unixtime_fieldname)) = MONTH(CURDATE())
	AND DAY(FROM_UNIXTIME(unixtime_fieldname)) = DAY(CURDATE())
	AND YEAR(FROM_UNIXTIME(unixtime_fieldname)) = YEAR(CURDATE())

This particular query is looking for any records that have the same month, day and year as today.

Related posts

Comments (1)

  1. Slowly but surely I’m reading through all the great information you have here on your blog. Thanks a lot for sharing, there are some awesome tips and tricks I found on your sites!

Leave a Reply