Remove time part of a timestamp

strtotime(date("Y-m-d", 1310571061));

That should do it for you.


Using a DateTime object can be helpful, and also can make the code more readable...

$dt = new DateTime();
$dt->setTimestamp(1310571061);
echo $dt->format('Y-m-d, H:i:s') . "\r\n";
$dt->setTime(0, 0, 0);
echo $dt->format('Y-m-d, H:i:s');

Result...

2011-07-14, 03:31:01

2011-07-14, 00:00:00

The choice of whether to use raw timestamps or DateTime objects will depend a lot on the implementation needs, but generally speaking DateTime objects will go a long way towards reducing confusion and errors that can crop up especially around Timezone issues and Daylight Saving Time issues.


In case you wanted a mathematical solution:

$time=1310571061;
echo floor($time/86400)*86400;

There are 86,400 seconds in 24 hours (which is the length of a typical day, but not all... see DST). Since our timestamps are in UTC, this shouldn't be a problem. You can divide that by the number of seconds in a day, drop the remainder, and multiply back out.