Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Show the date with hours, minutes and seconds set to zero [closed]

Tags:

date

php

format

I need a DateTime object that sets hours, minutes and seconds to '00:00:00'

Why does the following still output '20:53:19' instead of '00:00:00'?

const DATETIME_TO_MYSQL_DATETIME = 'Y-m-d H:i:s';
const DATE_FORMAT = 'j.n.Y';
    $this->today = DateTime::createFromFormat(self::DATE_FORMAT, (new DateTime())->format(self::DATE_FORMAT));
   die($this->today->format(self::DATETIME_TO_MYSQL_DATETIME));

Output: 2013-12-02 20:53:19

like image 664
Krab Avatar asked Sep 18 '25 09:09

Krab


2 Answers

Use:

const DATETIME_TO_MYSQL_DATETIME = 'Y-m-d 00:00:00';

if you want the hours/minutes/seconds to be 00:00:00, regardless of time.

like image 190
Wayne Whitty Avatar answered Sep 20 '25 22:09

Wayne Whitty


Just use:

$this->today = new DateTime('today');
like image 23
Glavić Avatar answered Sep 21 '25 00:09

Glavić