kba-team / sap-datetime
This package is abandoned and no longer maintained.
The author suggests using the php-sap/datetime package instead.
Extends PHP's DateTime class by SAP week, date and timestamp format.
v1.0.2
2019-01-17 10:28 UTC
Requires
- php: >=5.5.0
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is auto-updated.
Last update: 2022-02-01 13:15:11 UTC
README
Extends PHP's DateTime class by SAP week, date and timestamp format.
- SAP week in format
<year><week>
- SAP date in format
<year><month><day>
- SAP timestamp in format
<year><month><day><hour><minute><second>
Usage
composer require kba-team/sap-datetime:~1.0.0
Parse a SAP week string into a DateTime object.
<?php use kbATeam\SapDateTime\SapDateTime; $dateTime = SapDateTime::createFromFormat(SapDateTime::SAP_WEEK, '201846'); echo $dateTime->format('o \w\e\ek W') . PHP_EOL; /** * Output: 2018 week 46 */
Format a DateTime object as SAP week string
<?php use kbATeam\SapDateTime\SapDateTime; $dateTime = new SapDateTime('2018-10-19 08:09:10'); echo $dateTime->format(SapDateTime::SAP_WEEK) . PHP_EOL; /** * Output: 201842 */
Parse a SAP date string into a DateTime object
<?php use kbATeam\SapDateTime\SapDateTime; $dateTime = SapDateTime::createFromFormat(SapDateTime::SAP_DATE, '20181101'); echo $dateTime->format('Y-m-d') . PHP_EOL; /** * Output: 2018-11-01 */
Format a DateTime object as SAP date
<?php use kbATeam\SapDateTime\SapDateTime; $dateTime = new SapDateTime('2018-12-31 09:10:11'); echo $dateTime->format(SapDateTime::SAP_DATE) . PHP_EOL; /** * Output: 20181231 */
Parse a SAP timestamp into a DateTime object
<?php use kbATeam\SapDateTime\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 */
Format a DateTime object as SAP timestamp
<?php use kbATeam\SapDateTime\SapDateTime; $dateTime = new SapDateTime('2018-12-31 09:10:11'); echo $dateTime->format(SapDateTime::SAP_TIMESTAMP) . PHP_EOL; /** * Output: 20181231091011 */