Both of those options are pretty horrible -- if you're trying to get the current date at midnight as a formatted string, it's as simple as:
date('Y-m-d') . ' 00:00:00';
Or, if you want to be slightly more explicit,
date('Y-m-d H:i:s', strtotime('today midnight'));
No need to do that wacky mktime
thing. Whoever wrote that code does not know what they are doing and/or is a copy-paste/cargo-cult developer. If you really see that in "most examples," then the crowd you're hanging out with is deeply troubled and you should probably stop hanging out with them.
The only interesting thing that mktime
does is attempt to work with the local timezone. If your work is timezone sensitive, and you're working with PHP 5.3 or better, consider working with DateTime and DateTimeZone instead. A demo from the PHP interactive prompt:
php > $utc = new DateTimeZone('UTC');
php > $pdt = new DateTimeZone('America/Los_Angeles');
php > $midnight_utc = new DateTime('today midnight', $utc);
php > $midnight_utc->setTimeZone($pdt);
php > echo $midnight_utc->format('Y-m-d H:i:s');
2011-04-08 17:00:00
(At the moment, it is the 9th in UTC, while it's the 8th in PDT.)