PHP code example of kveugene / datetime

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

    

kveugene / datetime example snippets


composer install kveugene/datetime

use KVEugene\DateTime\DateTime;

// Extracts the hour from a natively DateTime object.
$date = new \DateTime();
$hour = (int) $date->format('H');

// Extracts the hour from a library DateTime object.
$date = new DateTime();
$hour = $date->hour;

// Sets the date to the first day of the month (natively)
$date = new \DateTime();
$date->setDate((int) $date->format('Y'), (int) $date->format('n'), 1);

// Sets the date to the first day of the month using a library.
$date = new DateTime();
$date->day = 1;

use KVEugene\DateTime\DateTime;
use KVEugene\DateTime\TimeOffset;

// Get the start date and time of the quarter: sliding mode.
$date = new DateTime()->sub(new TimeOffset('1q'));

// Get the start date and time of the current quarter in the Europe/Riga time zone.
$date = new DateTime()->sub(new TimeOffset('1q Europe/Riga'));

// Get the start date and time of the previous quarter in the Europe/Riga time zone.
$date = new DateTime()->sub(new TimeOffset('2q Europe/Riga'));