PHP code example of codeinc / datetime

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

    

codeinc / datetime example snippets



use CodeInc\DateTime\DateTime;

/*
 * Can be instantiated with a timestamp (checked with is_numeric())
 */
$dateTime = new DateTime(time());

/*
 * Provides methods to tests the current time
 */ 
$dateTime->isUndefined();
$dateTime->isPast();
$dateTime->isNow();
$dateTime->isFutur();

/*
 * Provides methods to get SQL dates
 */
$dateTime->getSqlDate(); // YYYY-MM-DD
$dateTime->getSqlDateTime(); // AAAA-MM-JJ HH:MM:SS

/*
 * Provides a method to get a RFC 1123 date 
 */
$dateTime->getRfc1123();

/*
 * The formats are available in class constants 
 */
$dateTime::FORMAT_SQL_DATE;
$dateTime::FORMAT_SQL_DATETIME;
$dateTime::FORMAT_RFC_1123;