By using a date object we can set time to any value by using setTime property this format
setTime( Hour, minutes, seconds )
All above inputs are in integer.
Here are some examples.

$date = new DateTime('2012-04-15 22:15:40');
echo $date->format('Y/m/d H:i:s') . "<br>";
echo $date->format('Y/m/d H:i:s') . "<br>";
The output is here
2012/04/15 22:15:40
2012/04/15 23:30:00
We can change the setTime to different values and output will change like this .
output is here
2012/04/15 22:15:40
2012/04/15 02:50:32

Procedural style

$date = date_create('2020-08-16');
date_time_set($date, 24, 56,58);
echo date_format($date, 'Y-m-d H:i:s');
2020-08-17 00:56:58
In the above code check how the hour has changed the day by adding one.
PHP Date Functions setDate() : Set date for date object Timestamp in PHP Displaying calendar for selection of date by user
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer