Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Unix Timestamp to Datetime in Laravel

How to convert Unix timestamp to Datetime in Laravel

🎈 🎈 🎈
+1

    use Carbon\Carbon;

    $timestamp = 1633028820; // Example Unix timestamp
    $date = Carbon::createFromTimestamp($timestamp);
    
    echo $date->toDateTimeString();                 
        

Output:
2021-09-30 19:07:00
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this code snippet, we are using Laravel's Carbon library to convert a Unix timestamp into a human-readable date format.
The Unix timestamp 1633028820 is passed to the Carbon::createFromTimestamp() method to create a Carbon date object.
This object allows for easy manipulation and formatting of dates. The toDateTimeString() method is then called on the Carbon object to convert the timestamp into a string representing the date and time in the format Y-m-d H:i:s.
In this example, it outputs the date 2021-09-30 19:07:00.



Other useful Laravel date functions

Function Description Example
now() Returns the current date and time as a Carbon instance. now() returns 2024-09-15 10:00:00
today() Returns the current date with time set to midnight as a Carbon instance. today() returns 2024-09-15 00:00:00
yesterday() Returns the date for yesterday with time set to midnight as a Carbon instance. yesterday() returns 2024-09-14 00:00:00
Carbon::parse() Parses a date string and returns a Carbon instance. Carbon::parse('2024-09-15') returns 2024-09-15 00:00:00
Carbon::createFromTimestamp() Creates a Carbon instance from a Unix timestamp. Carbon::createFromTimestamp(1633024800) returns 2021-10-01 00:00:00
addDays() Adds a specified number of days to the Carbon instance. now()->addDays(5) returns 2024-09-20 10:00:00
subMonths() Subtracts a specified number of months from the Carbon instance. now()->subMonths(2) returns 2024-07-15 10:00:00
diffForHumans() Returns a human-readable difference between the current time and another date. now()->subDays(3)->diffForHumans() returns 3 days ago
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder