PHP code example of baumrock / humandates

1. Go to this page and download the library: Download baumrock/humandates library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

baumrock / humandates example snippets


// manual download

// composer /autoload.php";

// create HumanDates instance
$dates = new HumanDates();
echo $dates->format("2023-01-01");              // 1. Jan 2023
echo $dates->range("2023-01-01", "2023-01-03"); // 1. - 3. Jan 2023

echo $dates->format("2023-01-01", "d.M.y"); // Output: 1.1.2023

// example using locale de_DE
echo $dates->range("2023-01-01", "2023-02-03"); // Output: 1. Jan. - 3. Feb. 2023
echo $dates->range("2023-01-01", "2023-01-03"); // Output: 1. - 3. Jan. 2023

// example using locale de_DE
echo $dates->range("2023-01-01", "2023-01-03", [
	'default'   => ['d. MMMM y', ' bis ', 'd. MMMM y'], // 1. Januar 2023 bis 3. Februar 2024
	'sameYear'  => ['d. MMMM',   ' bis ', 'd. MMMM y'], // 1. Januar bis 3. Februar 2023
	'sameMonth' => ['d.',        ' bis ', 'd. MMMM y'], // 1. bis 3. Januar 2023
	'sameDay'   => ['d. MMMM y'],                       // 1. Januar 2023
]);

echo $dates->setPatterns(...)->range(...);

$dates = new HumanDates("de_AT");
echo $dates->format($timestamp, "d. MMMM y"); // Output: 1. Jänner 2023

echo $dates->format(
  $timestamp,
  format: "d. MMMM y",
  locale: "de_DE",
); // Output: 1. Januar 2023

$dates = new HumanDates("de_AT", "dd.MM.y");
echo $dates->format("2023-1-1"); // Output: 01.01.2023
echo $dates->format("2023-1-1", "d. MMMM y"); // Output: 1. Jänner 2023