setTimestamp() to set ISO Date

setTimestamp ($unixtimestamp);
date_timestamp_set ($date_obj,$unixtimestamp);
ParameterDESCRIPTION
$date_objRequired : Input date object to be assigned new value.
$unixtimestampRequired: Integer , Timestamp of new date and time
Output is dateTime object after changing with new timestamp, FALSE on failure.

mktime() function to generate timestamp

Generate timestamp using date and time

Object Oriented style

$date = new DateTime();
$date->setTimestamp(1580774387);
echo $date->format('U = Y-m-d H:i:s'); // Output is 1580774387 = 2020-02-04 05:29:47

Procedural style

$date = date_create();
date_timestamp_set($date, 1671851396);
echo date_format($date, 'U = Y-m-d H:i:s') // Output is 1671851396 = 2022-12-24 08:39:56

Examples of Uses of Timestamp

Sometime we store timestamp of any event in an integer field in MySQL database instead of storing date and time. Say for example last login time of a user to your forum is stored in MySQL database. After collecting timestamp from table for the user, we can store the last login details like below. We have not discussed how to collect the data from MySQL here , you can read more on this in our MySQL section.
$last_login = new DateTime(); // create a date object 
$last_login->setTimestamp(1516245357); // Timestamp of 2018-01-18 08:45:57
$date = new DateTime();  // date object showing current time 
$date= $date->diff($last_login);
echo $date->format('%y Years, %m Months, %d Days'); //1 Years, 0 Months, 15 Days
The above output will change as the current date is changed.
We used date difference function.

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


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    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 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer