Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify DateTime object

Tags:

php

datetime

I create an object

$date = new DateTime();

It is set to current date 2011-04-01 21:43:40. I try the following

$date->modify('midnight');

I expect the object to set to 2011-04-01 00:00:00. But nothing happened. Object hadn't beed modified, and continue to have a 2011-04-01 21:43:40 date. I just want to reset the time to midnight (00:00:oo).

like image 535
Molfar Avatar asked Jul 17 '26 14:07

Molfar


1 Answers

http://codepad.org/w5RAF0Lh

This piece of code (with midnight) will not work without date.timezone setting

UPDATE: this piece of code requires PHP 5.3.6 to work correctly. In previous versions DateTime::modify('midnight') didn't work

like image 87
Vladislav Rastrusny Avatar answered Jul 19 '26 03:07

Vladislav Rastrusny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!