MySQL Match Dates with a UNIXTIME Field

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.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Related Posts

Tags: , ,

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





Donate

If you found this article useful and would like to see more like it this please consider making a donation.

Sponsors