PHP code example of arokettu / date

1. Go to this page and download the library: Download arokettu/date 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/ */

    

arokettu / date example snippets




use Arokettu\Date\Calendar;
use Arokettu\Date\Date;
use Arokettu\Date\JulianCalendar;
use Arokettu\Date\Month;

// creation
$date = Date::today(); // example: 2024-02-27
// or
$date = Calendar::create(2024, Month::February, 27);
// or
$date = Calendar::fromDateTime(new DateTime('Feb 27, 2024')); // truncates time
// or
$date = Calendar::parse('2024-02-27'); // Y-m-d is expected, years can be negative
// or
$date = Calendar::parseDateTimeString('Feb 27, 2024');

// alternative calendars
$date = JulianCalendar::parse('2024-02-14');

// getters
$date->getDay(); // 27
$date->getMonth(); // Month::February
$date->getMonthNumber(); // 2
$date->getYear(); // 2024
$date->getWeekDay(); // WeekDay::Tuesday
$date->getJulianDay(); // 2460368
$date->toDateTime(); // DateTimeImmutable('2024-02-27') // midnight in a default timezone
$date->toString(); // "2024-02-27"

// alternative calendar getters
$date->julian()->getDay(); // 14
$date->julian()->toString(); // "2024-02-14"