PHP code example of oneseven9955 / dateparser

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

    

oneseven9955 / dateparser example snippets


use OneSeven9955\DateParser\DateParser;
use OneSeven9955\DateParser\ParseException;

// Strict parse: an invalid date string will cause ParseException
try {
    $datetime = DateParser::from('30/04/2025')->parse(); // DateTime { date: 2015-04-30 00:00:00.0 UTC (+00:00) }
} catch (ParseException $ex) {
    printf("Unable to parse the date: %s\n", $ex->getMessage());
}

// Silent parse: an invalid date string will cause null as return value
$datetimeOrNull = DateParser::from('30#04#2025')->parseSilent(); // null