Home » PHP OOP » PHP DateTime

PHP DateTime

Summary : in this tutorial, you’ll learn how to work with the date and time in an object-oriented way.

Introduction to the PHP DateTime class

PHP provides a set of date and time classes that allow you to work with the date and time in an object-oriented way.

To create a new date and time object, you use the DateTime class. For example:

The DateTime object represents the current date and time in the timezone specified in the PHP configuration file ( php.ini )

To set a new timezone, you create a new DateTimeZone object and pass it to the setTimezone() method of the DateTime object:

In this example, we create a new DateTimeZone object and set it to "America/Los_Angeles" . To get valid timezones supported by PHP, check out the timezone list .

To format a DateTime object, you use the format() method. The format string parameters are the same as those you use for the date() function. For example:

To set a specific date and time, you can pass a date & time string to the DateTime() constructor like this:

Or you can use the setDate() function to set a date:

The time is derived from the current time. To set the time, you use the setTime() function:

Since the setDate() , setTime() , and setTimeZone() method returns the DateTime object, you can chain them like this which is quite convenient.

Creating a DateTime object from a string

When you pass the date string ’06/08/2021′ to the DateTime() constructor or setDate() function, PHP interprets it as m/d/Y . For example:

If you want to pass it as August 6th, 2021, you need to use the – or . instead of /. For example:

However, if you want to parse the date string ’06/08/2021′ as d/m/Y, you need to replace the / with – or . manually:

A better way to do it is to use the createFromFormat() static method of the DateTime object:

In this example, we pass the date format as the first argument and the date string as the second argument.

Note that when you pass a date string without the time, the DateTime() constructor uses midnight time. However, the createFromFormat() method uses the current time.

Comparing two DateTime objects

PHP allows you to compare two DateTime objects using the comparison operators including >, >=, <, <=, ==, <=>. For example:

Calculating the differences between two DateTime objects

The diff() method of the DateTime() object returns the difference between two DateTime() objects as a DateInterval object. For example:

The DateInterval represents the differences between two dates in the year, month, day, hour, etc. To format the difference, you use the DateInterval ‘s format. For example:

Check out all the DateInterval format parameters .

Adding an interval to a DateTime object

To add an interval to date, you create a new DateInterval object and pass it to the add() method. The following example adds 1 year 2 months to the date 01/01/2021 :

To format a date interval, you use the date interval format strings .

To subtract an interval from a DateTime object, you create a negative interval and use the add() method.

  • Use the DateTime class to work with the date and time.
  • Use the DateTimeZone class to work with time zones.
  • Use the comparison operators to compare two DateTime objects.
  • Use the diff() method to calculate the difference between to DateTime objects.
  • Use the DateInterval class to represent a date and time interval.
  • Use the add() method to add an interval to or subtract an interval from a DateTime object.

Date variable in PHP

:frowning:

Have a look at the date() function - http://php.net/manual/en/function.date.php and see how you get on…

As far as I know PHP does not have a date variable, maybe you mean a string?

http://php.net/manual/en/function.date.php

Thank you gandalf. I’ll try to assimilate it.

Thanks a lot John !

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.

  • Web Development

How to Set Value of HTML "date" input Element Using PHP?

  • Daniyal Hamid
  • 16 Oct, 2022

The HTML <input type="date"> element expects the value attribute to be set in " YYYY-MM-DD " format. Therefore, if you're setting a default value to it using PHP, then you must adhere to the correct date format (i.e. " Y-m-d " in PHP).

For example, you can set the current date using DateTime (or DateTimeImmutable ), in the following way:

Similarly, you can set a specific date using DateTime (or DateTimeImmutable ), in the following way:

There are several other ways in which you can create a formatted date in PHP. For example, you may use the date_create() function as an alternative, which creates a new DateTime object:

This post was published 16 Oct, 2022 by Daniyal Hamid . Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post .

IncludeHelp_logo

  • Data Structure
  • Coding Problems
  • C Interview Programs
  • C++ Aptitude
  • Java Aptitude
  • C# Aptitude
  • PHP Aptitude
  • Linux Aptitude
  • DBMS Aptitude
  • Networking Aptitude
  • AI Aptitude
  • MIS Executive
  • Web Technologie MCQs
  • CS Subjects MCQs
  • Databases MCQs
  • Programming MCQs
  • Testing Software MCQs
  • Digital Mktg Subjects MCQs
  • Cloud Computing S/W MCQs
  • Engineering Subjects MCQs
  • Commerce MCQs
  • More MCQs...
  • Machine Learning/AI
  • Operating System
  • Computer Network
  • Software Engineering
  • Discrete Mathematics
  • Digital Electronics
  • Data Mining
  • Embedded Systems
  • Cryptography
  • CS Fundamental
  • More Tutorials...
  • 📚Tech Articles
  • 🤩Full Forms
  • ☕Code Examples
  • 📰Guest Post
  • ⌨Programmer's Calculator
  • 🥰XML Sitemap Generator
  • 🥰Tools & Generators

IncludeHelp

Home » PHP » PHP Programs

  • PHP code to assign and print the current date time in variables

In this PHP code, we will learn how to get and assign current date time into variables and print them on the webpage?

Source Code and Output to Get, Assign and print Current Date and Time

The following PHP topics are used in the above examples:

  • PHP basic syntax
  • PHP print() statement
  • PHP variables

PHP Basic Programs »

Related Programs

  • PHP Code to print text using print command
  • PHP Code to print text using echo command
  • PHP program to create a function to find the addition of two integer numbers
  • PHP Code to print current date in various formats
  • PHP Code to print current time in various formats
  • PHP code to get total number of days in a month
  • How to make text bold in PHP?
  • How to break a foreach loop in PHP?
  • PHP code to get time difference
  • PHP code to get number of days between two dates
  • PHP program to check whether given number is palindrome or not
  • Check Even and ODD in PHP
  • Find factorial of a number in PHP
  • Calculate difference between dates in PHP
  • PHP code to make a dynamic countdown timer
  • PHP code to create tables dynamically from user input
  • PHP code to reverse an integer number
  • PHP program to find integer division using intdiv() function
  • PHP program to handle modulo by zero exception
  • PHP program to generate a random integer between the ranges
  • PHP program to print the table of a given number using recursion
  • PHP program to calculate the factorial of a given number using recursion
  • PHP program to calculate the power of a given number using recursion
  • PHP program to calculate factors of a given number

All PHP Programs

  • PHP program to check whether given number is palindrome or not.
  • Check Even and ODD in PHP.
  • Find factorial of a number in PHP.
  • PHP minor project for Student Result Management System
  • PHP program to find the maximum and minimum element of an array
  • Appending/merging of two arrays in PHP
  • How to get the length of the array in PHP?
  • Delete an element from an array in PHP
  • Create an associative array in PHP
  • How to get the only values from an associative array in PHP?
  • PHP program to sort an integer array in ascending and descending order
  • PHP | Delete an element from an array using unset() function
  • PHP | Delete all occurrences of an element from an array
  • PHP | Find the occurrences of a given element in an array
  • Check if an array is empty or not in PHP
  • Concatenating two strings in PHP
  • How to convert array into string in PHP?
  • Check if string contains a particular character in PHP
  • How to convert a string to uppercase in PHP?
  • PHP program to convert string to uppercase without using the library function
  • PHP program to convert string to lowercase without using the library function
  • PHP | Check whether a specific word/substring exists in a string
  • PHP | Reverse a given string without using the library function
  • PHP | Split comma delimited string into an array without using library function
  • PHP | Create comma delimited string from an array without using library function
  • PHP | Convert a string to character array
  • PHP | Count the total number of words in a string
  • PHP program to replace a word in a string
  • PHP program to remove special characters from a string
  • PHP program to create an object of a class and access the class attributes
  • PHP program to create multiple objects of a class and access attributes of the class
  • PHP program to define methods within the class
  • PHP program to initialize data members without using the constructor
  • PHP program to print the size of the empty class
  • PHP program to create a class with setter and getter functions
  • PHP program to create a class to add two distances
  • PHP program to create a class to subtract one distance from another distance
  • PHP program to create a class to add two times
  • PHP program to convert seconds into hours, minutes, and seconds
  • PHP program to convert hours, minutes, and seconds into several seconds
  • PHP program to implement a cascaded function call
  • PHP program to create a constant using define() function
  • PHP program to create a case in-sensitive constant using define() function
  • PHP program to check a constant is defined or not
  • PHP program to print the line number using __LINE__ magic constant
  • PHP program to print the full path of the current program file
  • PHP program to print the function name using magic constant __FUNCTION__
  • PHP program to print the class name using magic constant __CLASS__
  • PHP program to print the method name with the associated class name using magic constant __METHOD__
  • PHP program to demonstrate the use of printf() function
  • PHP program to demonstrate the use of the local and global variables
  • PHP program to demonstrate the default or no-argument constructor
  • PHP program to implement the default or no-argument constructor using __construct()
  • PHP program to demonstrate the parameterized constructor
  • PHP program to implement the parameterized constructor using __construct()
  • PHP program to demonstrate the use of destructor
  • PHP program to demonstrate the call by value parameter passing
  • PHP program to demonstrate the call by reference parameter passing
  • PHP program to demonstrate the use of default arguments
  • PHP program to demonstrate the use of variable arguments
  • PHP program to demonstrate the single inheritance
  • PHP program to call a base class constructor from the derived class
  • PHP program to call base class destructor from the derived class
  • PHP program to demonstrate the multi-level inheritance
  • PHP program to demonstrate the hierarchical or tree inheritance
  • PHP program to demonstrate the example of a simple interface
  • PHP program to implement an interface into multiple classes
  • PHP program to implement multiple interfaces in the same class
  • PHP program to implement multiple-inheritance using the interface
  • PHP program to demonstrate the inheritance of interfaces
  • PHP program to demonstrate the example of the simple abstract class
  • PHP program to inherit an abstract class into multiple non-abstract classes
  • PHP program to inherit an abstract class and an interface in a non-abstract class
  • PHP program to demonstrate the inheritance of abstract classes
  • PHP program to demonstrate the method overriding
  • PHP program to demonstrate the final keyword
  • PHP program to demonstrate the method overloading based on the number of arguments
  • PHP programs to pass an object of class as an argument
  • PHP programs to demonstrate the function returning object
  • PHP program to demonstrate the Divide By Zero Exception using exception handling
  • PHP program to demonstrate the Array index out of bound exception using exception handling
  • PHP program to demonstrate the NULL reference exception using exception handling
  • PHP program to create a user-defined exception class
  • PHP program to create DivideByZeroException class
  • PHP program to demonstrate the finally block in exception handling
  • PHP program to demonstrate the use of multiple catch blocks
  • PHP program to convert an associated array into JSON format
  • PHP program to demonstrate the json_encode() function with indexed array of strings
  • PHP program to demonstrate the json_encode() function with multi-dimensional array
  • PHP program to decode the JSON string into an associative array
  • PHP program to decode the JSON string into a multi-dimensional array
  • PHP program to check a substring exists within the given string using a regular expression pattern
  • PHP program to check a case insensitive substring exists within the given string using regular expression pattern
  • PHP program to demonstrate the regular expression to count the occurrence of given substring
  • PHP program to demonstrate the regular expression to replace the substring within the string
  • PHP program to demonstrate the quantifiers in pattern to search a string using a regular expression
  • PHP code to connect various databases
  • PHP example to fetch data from MySQL (MariaDB) database using PDO function
  • PHP PDO Inserting data into tables
  • PHP Invoice Example
  • PHP Code to Insert Data in MySql
  • PHP - MySql Connection Example
  • Display source code of the website with PHP
  • Get the contents of a directory in PHP
  • Setting Cookies in PHP
  • How to pass values between the pages in PHP?
  • How to redirect to another page in PHP?
  • Very useful PHP code snippets for PHP Developer
  • PHP program to validate an email address
  • How to detect search engine bots with PHP?
  • PHP program to calculate the md5 hash from plaintext
  • PHP program to convert a string into base64
  • PHP program to convert base64 into the simple string
  • PHP program to send a text e-mail message
  • PHP program to send an HTML email message
  • PHP program to download the text file from the specified URL
  • PHP program to demonstrate the use of $GLOBALS to access global variables
  • PHP program to print the filename of the current executing PHP script
  • PHP program to print the version of CGI used by the webserver
  • PHP program to print the IP address of a hosted web server
  • PHP program to print the server name or website name
  • PHP program to print the version of the server software
  • PHP program to print the server protocol
  • PHP program to print the request method used to access the webpage
  • PHP program to print the timestamp of the start of the request
  • PHP program to demonstrate the use of $_REQUEST superglobal variable
  • PHP program to demonstrate the use of $_POST superglobal variable
  • Write a PHP script to get the PHP version and configuration information
  • Write a PHP script to display the strings as per the given sample strings
  • Using PHP Variable in HTML: Title, H3, and Anchor Text Example
  • PHP Script for Extracting URL Components: Scheme, Host, and Path
  • Write a PHP script for Browser Detection
  • Write a PHP script, which changes the color of the first character of a word
  • PHP Check HTTPS or HTTP: Simple Guide for Web Developers
  • How to pass an array via $_GET in PHP?
  • How do you get the last modified information of a file using PHP?
  • How to count the number of lines in a file using PHP?
  • PHP program to read and display text from a file
  • PHP program to write text to a file
  • Create files with encrypted and decrypted data from a file in PHP
  • PHP - How to get the first day of the current year?
  • PHP - Check if a file exists or not
  • How to rename a file in PHP?
  • PHP - Copy a file from one directory to another
  • PHP - Copy the entire contents of a directory to another directory
  • How to create a temporary file in PHP?

Comments and Discussions!

Load comments ↻

  • Marketing MCQs
  • Blockchain MCQs
  • Artificial Intelligence MCQs
  • Data Analytics & Visualization MCQs
  • Python MCQs
  • C++ Programs
  • Python Programs
  • Java Programs
  • D.S. Programs
  • Golang Programs
  • C# Programs
  • JavaScript Examples
  • jQuery Examples
  • CSS Examples
  • C++ Tutorial
  • Python Tutorial
  • ML/AI Tutorial
  • MIS Tutorial
  • Software Engineering Tutorial
  • Scala Tutorial
  • Privacy policy
  • Certificates
  • Content Writers of the Month

Copyright © 2024 www.includehelp.com. All rights reserved.

Date Format in PHP for Insertion in MySQL

  • Date Format in PHP for Insertion in …

date() in PHP

Date_format() in php.

Date Format in PHP for Insertion in MySQL

MySQL is an RDBMS database intended to store relational data. It supports various data types, Date being one of them. As MySQL supports only particular date formats, you need to format the dates before inserting dates into the DB; otherwise, the DB will throw an error.

This article will introduce how to format dates in PHP before inserting them into a MySQL DB.

MySQL supports 5 date formats.

  • DATE : YYYY-MM-DD It only stores the date without time in the range of 1000-01-01 to 9999-12-31 . For example, 2021-10-28 .
  • DATETIME : YYYY-MM-DD HH:MI:SS . It stores the date with time in the range of 1000-01-01 00:00:00 to 9999-12-31 23:59:59 . For example, 2021-10-28 10:30:24
  • TIMESTAMP : YYYY-MM-DD HH:MI:SS . It stores the date with time in the range of 1970-01-01 00:00:01 to 2038-01-09 03:14:17 . For example, 2021-10-28 10:30:24
  • TIME : HH:MI:SS . It stores the time without date in the range of -838:59:59 to 838:59:59 . For example, 10:30:24
  • YEAR : YYYY or YY . It stores the year either 4 digits or 2 digits in the range of 70(1970)-69(2069) for 2 digits and 1901-2155 | 0000 for 4 digits. For example, 2021 .

Before learning the solution, let’s understand the concept of date() .

It is a built-in PHP function that returns the formatted date string.

Syntax of date()

$format : This is a mandatory parameter that specifies the output date string format. Some of the options are:

  • d - The day of the month in the range of 01 to 31
  • m - A numeric representation of a month in the range of 01 to 12
  • Y - A four-digit representation of a year
  • y - A two-digit representation of a year
  • H - A two-digit representation of an hour in the range of 00 to 23
  • i - A two-digit representation of a minute in the range of 00 to 59
  • s - A two-digit representation of a second in the range of 00 to 59

$timestamp : It is an optional parameter that specifies a Unix timestamp in integer format. If not provided, a default value will be taken as the current local time.

Example code:

It is a built-in PHP function that takes the DateTime object as input and returns the formatted date string.

Syntax of date_format()

$dateObject : It is a mandatory parameter that specifies a DateTime object.

Shraddha Paghdar avatar

Shraddha is a JavaScript nerd that utilises it for everything from experimenting to assisting individuals and businesses with day-to-day operations and business growth. She is a writer, chef, and computer programmer. As a senior MEAN/MERN stack developer and project manager with more than 4 years of experience in this sector, she now handles multiple projects. She has been producing technical writing for at least a year and a half. She enjoys coming up with fresh, innovative ideas.

Related Article - PHP MySQL

  • How to Describe Database Table With Mysqli_query in PHP
  • How to Insert Special Characters Into a Database in PHP
  • How to Execute Multiple MySQL Queries in PHP
  • How to Set Up a Search System With PHP and MySQL
  • How to Export MySQL Table to Excel in PHP

PHP Tutorial

Php advanced, mysql database, php examples, php reference, php date_add() function.

❮ PHP Date/Time Reference

Add 40 days to the 15th of March, 2013:

Definition and Usage

The date_add() function adds some days, months, years, hours, minutes, and seconds to a date.

Parameter Values

Advertisement

Technical Details

Get Certified

COLOR PICKER

colorpicker

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

[email protected]

Top Tutorials

Top references, top examples, get certified.

  • Function Reference
  • Date and Time Related Extensions

DateTime::setTime

Date_time_set.

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

DateTime::setTime -- date_time_set — Sets the time

Description

Object-oriented style

Procedural style

Resets the current time of the DateTime object to a different time.

Like DateTimeImmutable::setTime() but works with DateTime .

The procedural version takes the DateTime object as its first argument.

Procedural style only: A DateTime object returned by date_create() . The function modifies this object.

Hour of the time.

Minute of the time.

Second of the time.

Microsecond of the time.

Return Values

Returns the modified DateTime object for method chaining.

  • DateTimeImmutable::setTime() - Sets the time

User Contributed Notes

To Top

IMAGES

  1. How to use the date() Function in PHP

    php assign date

  2. PHP: Date Function

    php assign date

  3. Date Function in PHP

    php assign date

  4. Formatting Date and Time in PHP

    php assign date

  5. Display Date in PHP / Date Format In PHP / How to Get Date From

    php assign date

  6. PHP Function: Date and Time Example

    php assign date

VIDEO

  1. php://input

  2. PHP : Conditions

  3. Understanding PHP Data Types

  4. Php Lesson Update Database

  5. 034 php forms part1

  6. Office Left Karte Time jab Boss Extra Kaam Assign Kar De Tab Mera Expression #coding #software

COMMENTS

  1. PHP Date and Time

    Get a Date The required format parameter of the date () function specifies how to format the date (or time). Here are some characters that are commonly used for dates: d - Represents the day of the month (01 to 31) m - Represents a month (01 to 12) Y - Represents a year (in four digits) l (lowercase 'L') - Represents the day of the week

  2. PHP: date

    PHP Manual Function Reference Date and Time Related Extensions Date/Time Date/Time Functions Change language: Submit a Pull Request Report a Bug date (PHP 4, PHP 5, PHP 7, PHP 8) date — Format a Unix timestamp Description ¶ date ( string $format, ? int $timestamp = null ): string

  3. php

    $day1 = new DateTime (); $day1->modify ('-1357 days'); //if you need it to be some fixed date, use $day1= new DateTime ("2011-08-01"); $now_date = new DateTime (); for ($i=0;$i<10;$i++) { $date_diff = $now_date->diff ($zero_date); $prevdays = $date_diff->format ("#a")-$i; print ('<input type="submit" name="bugun" value="'.$prevdays.'"> '); }

  4. PHP date() Function

    Definition and Usage The date () function formats a local date and time, and returns the formatted date string. Syntax date ( format, timestamp) Parameter Values Technical Details PHP Date/Time Reference W3schools Pathfinder Track your progress - it's free! Log in Sign Up

  5. PHP: DateTime

    Calling methods on objects of the class DateTime will change the information encapsulated in these objects, if you want to prevent that you will have to use clone operator to create a new object. Use DateTimeImmutable instead of DateTime to obtain this recommended behaviour by default. Class synopsis ¶

  6. PHP: DateTime::modify

    Procedural style date_modify ( DateTime $object, string $modifier ): DateTime |false Alter the timestamp of a DateTime object by incrementing or decrementing in a format accepted by DateTimeImmutable::__construct () . Parameters ¶ object Procedural style only: A DateTime object returned by date_create () . The function modifies this object.

  7. A comprehensive guide to handling dates and times in PHP

    This limitation arises from the utilization of a 32-bit signed integer for date and time management. To ensure greater accuracy, it is advised to employ the DateTime class family. Working with dates in PHP. PHP provides a DateTime class with a rich set of methods for manipulating them. In this section, I will explore these methods and what they ...

  8. PHP DateTime

    Summary: in this tutorial, you'll learn how to work with the date and time in an object-oriented way.. Introduction to the PHP DateTime class. PHP provides a set of date and time classes that allow you to work with the date and time in an object-oriented way.

  9. PHP Date/Time Functions

    The date/time functions allow you to get the date and time from the server where your PHP script runs. You can then use the date/time functions to format the date and time in several ways. Note: These functions depend on the locale settings of your server. Remember to take daylight saving time and leap years into consideration when working with ...

  10. PHP: date_create

    A. Go ¶ 4 years ago Notice php by default assume the give string as such format: '-' is 'y-m-d' '/' is 'm/d/y' Unless the given string has Y or M, that is year is written as full year '2019', or month is written as English shorthand 'Jan', the default assumption will be applied, where the date might be incorrect.

  11. Date variable in PHP

    Date variable in PHP deotpit May 19, 2017, 6:35am 1 Hi everyone, I'd like to create a variable : "$myDate" of date type with a value attached: "2001-01-31" which is 31th January 2001. Problem...

  12. How to Set Value of HTML "date" input Element Using PHP?

    Therefore, if you're setting a default value to it using PHP, then you <em>must</em> adhere to the correct date format (i.e. "<code>Y-m-d</code>" in PHP). </p> <p> For example, you can set the <em>current</em> date using <code>DateTime</code> (or <code>DateTimeImmutable</code>), in the following way: </p> <pre> $dt = new DateTime (); echo '<...

  13. PHP code to assign and print the current date time in variables

    PHP code to assign and print the current date time in variables In this PHP code, we will learn how to get and assign current date time into variables and print them on the webpage? Source Code and Output to Get, Assign and print Current Date and Time

  14. PHP: DateTime::setDate

    Procedural style date_date_set ( DateTime $object, int $year, int $month, int $day ): DateTime Resets the current date of the DateTime object to a different date. Like DateTimeImmutable::setDate () but works with DateTime, and changes the existing object. The procedural version takes the DateTime object as its first argument. Parameters ¶ object

  15. Date Format in PHP for Insertion in MySQL

    This article will introduce how to format dates in PHP before inserting them into a MySQL DB. MySQL supports 5 date formats. DATE: YYYY-MM-DD It only stores the date without time in the range of 1000-01-01 to 9999-12-31.For example, 2021-10-28. DATETIME: YYYY-MM-DD HH:MI:SS.It stores the date with time in the range of 1000-01-01 00:00:00 to 9999-12-31 23:59:59.

  16. php

    2 Answers Sorted by: 0 You can do something like <?php $timestamp = time (); $date = date ( "Y-m-d", $timestamp ); ?> <input type="date" value="<?php echo $date; ?>" name="date"> Explanation

  17. Convert from MySQL datetime to another format with PHP

    Jan 15, 2014 at 11:25 3 Can I recommend and alternative to your date format? mm/dd/yy is very American, and those of us living in other parts of the world get more than a little irritable on trying to second-guess what is meant by 11-12-13. The more universal standard is yyyy-mm-dd, and is part of the ISO 8601 standard.

  18. PHP date_add() Function

    Definition and Usage The date_add () function adds some days, months, years, hours, minutes, and seconds to a date. Syntax date_add ( object, interval) Parameter Values Technical Details PHP Date/Time Reference W3schools Pathfinder Track your progress - it's free! Log in Sign Up COLOR PICKER

  19. PHP: DateTime::setTime

    Procedural style date_time_set ( DateTime $object, int $hour, int $minute, int $second = 0, int $microsecond = 0 ): DateTime Resets the current time of the DateTime object to a different time. Like DateTimeImmutable::setTime () but works with DateTime . The procedural version takes the DateTime object as its first argument. Parameters ¶ object