PHP code example of php-sap / datetime
1. Go to this page and download the library: Download php-sap/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/ */
php-sap / datetime example snippets
use phpsap\DateTime\SapDateTime;
$dateTime = SapDateTime::createFromFormat(SapDateTime::SAP_WEEK, '201846');
echo $dateTime->format('o \w\e\ek W') . PHP_EOL;
/**
* Output: 2018 week 46
*/
use phpsap\DateTime\SapDateTime;
$dateTime = new SapDateTime('2018-10-19 08:09:10');
echo $dateTime->format(SapDateTime::SAP_WEEK) . PHP_EOL;
/**
* Output: 201842
*/
use phpsap\DateTime\SapDateTime;
$dateTime = SapDateTime::createFromFormat(SapDateTime::SAP_DATE, '20181101');
echo $dateTime->format('Y-m-d') . PHP_EOL;
/**
* Output: 2018-11-01
*/
use phpsap\DateTime\SapDateTime;
$dateTime = new SapDateTime('2018-12-31 09:10:11');
echo $dateTime->format(SapDateTime::SAP_DATE) . PHP_EOL;
/**
* Output: 20181231
*/
use phpsap\DateTime\SapDateTime;
$dateTime = SapDateTime::createFromFormat(SapDateTime::SAP_TIME, '132001');
echo $dateTime->format('H:i:s') . PHP_EOL;
/**
* Output: 13-20-01
*/
use phpsap\DateTime\SapDateInterval;
$time = SapDateInterval::createFromDateString('252003');
echo $time->format('%H:%I:%S') . PHP_EOL;
/**
* Output: 25:20:03
*/
$date = new DateTime('2018-11-01 00:00:00');
$date->add($time);
echo $date->format('Y-m-d H:i:s');
/**
* Output: 2018-11-02 01:20:03
*/
use phpsap\DateTime\SapDateTime;
$dateTime = new SapDateTime('21:45:05');
echo $dateTime->format(SapDateTime::SAP_TIME) . PHP_EOL;
/**
* Output: 214505
*/
use phpsap\DateTime\SapDateInterval;
$time = new SapDateInterval('PTH21M45S05');
echo $time->format(SapDateInterval::SAP_TIME) . PHP_EOL;
/**
* Output: 214505
*/
use phpsap\DateTime\SapDateTime;
$dateTime = SapDateTime::createFromFormat(SapDateTime::SAP_TIMESTAMP, '20181019080910');
echo $dateTime->format('Y-m-d H:i:s') . PHP_EOL;
/**
* Output: 2018-10-19 08:09:10
*/
use phpsap\DateTime\SapDateTime;
$dateTime = new SapDateTime('2018-12-31 09:10:11');
echo $dateTime->format(SapDateTime::SAP_TIMESTAMP) . PHP_EOL;
/**
* Output: 20181231091011
*/
composer