Tutorial by Examples

getTimeStemp is a unix representation of a datetime object. $date = new DateTime(); echo $date->getTimestamp(); this will out put an integer indication the seconds that have elapsed since 00:00:00 UTC, Thursday, 1 January 1970.
setDate sets the date in a DateTime object. $date = new DateTime(); $date->setDate(2016, 7, 25); this example sets the date to be the twenty-fifth of July, 2015, it will produce the following result: 2016-07-25 17:52:15.819442
We can use the class DateInterval to add or subtract some interval in a DateTime object. See the example below, where we are adding an interval of 7 days and printing a message on the screen: $now = new DateTime();// empty argument returns the current date $interval = new DateInterval('P7D');//th...
PHP is able to parse a number of date formats. If you want to parse a non-standard format, or if you want your code to explicitly state the format to be used, then you can use the static DateTime::createFromFormat method: Object oriented style $format = "Y,m,d"; $time = "2009,2,26&...
PHP 4+ supplies a method, format that converts a DateTime object into a string with a desired format. According to PHP Manual, this is the object oriented function: public string DateTime::format ( string $format ) The function date() takes one parameters - a format, which is a string Format T...
To create \DateTimeImmutable in PHP 5.6+ use: \DateTimeImmutable::createFromMutable($concrete); Prior PHP 5.6 you can use: \DateTimeImmutable::createFromFormat(\DateTime::ISO8601, $mutable->format(\DateTime::ISO8601), $mutable->getTimezone());

Page 1 of 1