Create current php date date without seconds

I need a date object that has a time of 12:00:00 in the morning for the current day (which means not seconds). I convert this to this number in number of seconds and passing it to another function. It is ultimately used to filter reports using date = "someDateHere" from the database, and hanging seconds in the field spin the report.

I'm not sure what to include the second parameter in the time function - leaving it empty will use the current time, which I do not want. I can not find examples or anything in php doc. If there is another function that will do the job, I will be open to suggestions. It should be simple, but it alludes to me.

        date_default_timezone_set('America/Detroit');
        $now = date("Y-m-d 0:0:0");
        echo $now . '<br/>';
        $now = time($now,0);
        echo $now . '<br/>';

Thanks in advance.

edit: Note: I need to convert this date object in seconds. It is there that the timestamp wraps me up with the strtotime function and the time function. Despite the fact that I pass it a date object without a timestamp, converting it to seconds is not so convenient, insert the timestamp as the second parameter, which defaults to the current time.

+5
source share
4 answers

Many options are available here, since PHP allows a wide variety of time formats.

$midnight = strtotime('midnight');
$midnight = strtotime('today');
$midnight = strtotime('12:00am');
$midnight = strtotime('00:00');
// etc.

Or in the form of a DateTime :

$midnight = new DateTime('midnight');
$midnight = new DateTime('today');
$midnight = new DateTime('12:00am');
$midnight = new DateTime('00:00');
// etc.

See time formats and relative formats in the manual for a complete list of formats with descriptions.

+6
source

, DateTime!

$date = new DateTime("now", new DateTimeZone("America/Detroit"));
echo $date->format("Y-m-d");

http://php.net/manual/en/class.datetime.php

+2

time () takes no arguments. what you do is pointless. why not just strtotime(date('Y-m-d'))get the unix timestamp after midnight?

+1
source

I think mktime () is exactly what you need http://www.php.net/manual/en/function.mktime.php

<?php
// Set the default timezone to use. Available as of PHP 5.1
date_default_timezone_set('UTC');

// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));

// Prints something like: 2006-04-05T01:02:03+00:00
echo date('c', mktime(1, 2, 3, 4, 5, 2006));
?>
0
source

All Articles