Date

jenssegers/date image

Date stats

Downloads
7.6M
Stars
1,811
Open Issues
6
Forks
248

View on GitHub →

A date library to help you work with dates in different languages

Laravel Date Package Summary

The Laravel Date package, created by Jens Segers, is an extension of the popular Carbon library, designed to add robust multi-language support for date and time operations within Laravel applications. This package leverages the comprehensive localization capabilities of Carbon to provide developers with an easy way to handle date-time values across different languages.

Key Features

  • Multi-language Support: Harnesses Carbon's language files to render date and time information in various languages.
  • Extended Carbon Methods: Includes enhanced versions of Carbon's methods such as format, diffForHumans, parse, and createFromFormat to support multi-language contexts.
  • Automatic Localization: Integrates seamlessly with Laravel, automatically adapting to the application's locale settings.
  • Additional Tools: Offers new methods like timespan and aliases like ago (for diffForHumans) to simplify common tasks.

Installation

To install the package, use Composer:

composer require jenssegers/date

Laravel Integration

For Laravel 5.5 and newer, the package uses auto-discovery to register the service provider and facade. For older versions, you need to manually add the service provider and facade in config/app.php:

'providers' => [
Jenssegers\Date\DateServiceProvider::class,
];
 
'aliases' => [
'Date' => Jenssegers\Date\Date::class,
];

Usage

Set the locale and use Date methods to manipulate and display date-time values:

use Jenssegers\Date\Date;
 
// Set locale
Date::setLocale('nl');
 
// Display current time in Dutch
echo Date::now()->format('l j F Y H:i:s'); // Outputs: zondag 28 april 2013 21:58:16
 
// Time difference in a human-readable format
echo Date::parse('-1 day')->diffForHumans(); // Outputs: 1 dag geleden
 
// Timespan method example
echo $date->timespan(); // Outputs: 3 months, 1 week, 1 day, 3 hours, 20 minutes

Supported Languages

The package includes extensive language support, matching the locales supported by Carbon. Examples include English, Spanish, Dutch, and many more. See the full list in the package documentation or on the Carbon documentation site.

Additional Information

While the Date package extends Carbon's functionality, all original methods and functionalities of Carbon are still accessible. For detailed usage of Carbon’s methods, refer to the Carbon documentation.

Contributions related to language translations should be directed to the Carbon repository.


For developers looking to handle date and time values in multiple languages within Laravel, the Date package offers an efficient and straightforward solution, building on the solid foundation provided by Carbon.

jenssegers photo

Engineering Manager & Solution Architect at OTA Insight

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Jenssegers Date Related Articles

Build a Laravel Scout Search Endpoint With the HTTP QUERY Method image

Build a Laravel Scout Search Endpoint With the HTTP QUERY Method

Read article
Find the Security Vulnerabilities in Your Laravel App with Sensagraph image

Find the Security Vulnerabilities in Your Laravel App with Sensagraph

Read article
HTTP Query Method Support in Laravel 13.19 image

HTTP Query Method Support in Laravel 13.19

Read article
USAIGE: Track Token Usage and Costs for Laravel AI SDK Requests image

USAIGE: Track Token Usage and Costs for Laravel AI SDK Requests

Read article
Help make Filament faster! image

Help make Filament faster!

Read article
Monitor Laravel Queues, Commands, and Schedulers on Any Driver with Vigilance image

Monitor Laravel Queues, Commands, and Schedulers on Any Driver with Vigilance

Read article
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media