Before I post this question, I searched in several places for answer for this. I really could not find the proper answer.
I evaluated the both way following...
$date = new DateTime()
amd
$date = new DateTime('NOW')
Is it must for the both above give the same result or is there any circumstance they both differ?
The DateTime::format() function is an inbuilt function in PHP which is used to return the new formatted date according to the specified format.
It is a PHP function that "returns the date & time in the same format as the MySQL function NOW()", which is precisely the question.
PHP date_diff() Function $date2=date_create("2013-12-12"); $diff=date_diff($date1,$date2);
If you'll look into DateTime
constructor definition you'll see that now
is default value for initializing string:
public DateTime::__construct() ([ string $time = "now" [, DateTimeZone $timezone = NULL ]] )
That means both two calls above are always equal. If you'll not specify anything as initializing string, PHP will substitute now
implicitly for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With