From: Pintér Tibor Date: February 24 2011 5:06pm Subject: Re: Get date from unix_timestamp only up to the hour List-Archive: http://lists.mysql.com/mysql/224499 Message-Id: <4D66901F.90109@tibyke.hu> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 02/24/2011 05:41 PM, Bryan Cantwell wrote: > How would I go about modifying a unix timestamp to actually represent > the 'top of the hour' that it represents? > For instance: > 1296158500 = 1/27/2011 2:01:40 PM > That is in the 2:00 pm hour, how can I find that out and modify it to > 1296158400 which = 1/27/2011 2:00:00 PM? something like this: mysql> set @now:=now(), @foo:=unix_timestamp(); select @now, @foo, @foo - minute(@now) * 60 - second(@now) as hour_unix, from_unixtime(@foo - minute(@now) * 60 - second(@now)); Query OK, 0 rows affected (0.00 sec) +---------------------+------------+------------+--------------------------------------------------------+ | @now | @foo | hour_unix | from_unixtime(@foo - minute(@now) * 60 - second(@now)) | +---------------------+------------+------------+--------------------------------------------------------+ | 2011-02-24 18:06:24 | 1298567184 | 1298566800 | 2011-02-24 18:00:00 | +---------------------+------------+------------+--------------------------------------------------------+ 1 row in set (0.00 sec) t