echodatetime (function)

Last updated: Mon, Apr 17, 2023 7:46 am
Return to Knowledgebase





# Parameter Data Type Required Description
1 $ts string Yes A string representing a timestamp in any format that can be recognized by the strtotime function, such as "2022-04-18 10:30:00" or "April 18th, 2022 10:30am".


Data Type Description of Returned Data
string Returns a formatted date string indicating the time difference between the given timestamp and the current time.

Further Documentation:

The function first converts the given timestamp to a Unix timestamp using the strtotime function. Then it calculates the time difference in days between the current time and the given timestamp.

If the time difference is between 0 and 7 days, the function returns a string indicating the time elapsed in days and the time of day (either "Today, HH:MM AM/PM" or the day of the week followed by the time in the same format).

If the time difference is 7 days or greater, the function returns a string indicating the date and time in the format "MMM DD, YYYY HH:MM AM/PM".

Here's an example of how to use the function:

$timestamp = '2022-04-01 14:30:00';
$dateString = echodatetime($timestamp);
echo $dateString; // Output: "Apr 1, 2022 2:30 PM"