themeisee / mssql-time-converter
This package is abandoned and no longer maintained.
No replacement package was suggested.
Converts float type to DateTime
dev-master
2018-08-02 12:36 UTC
Requires
- php: ^7.0
This package is not auto-updated.
Last update: 2020-02-28 20:20:05 UTC
README
Converts float type to DateTime object. Uses in MSSQL, so you can make query
SELECT CAST(43243.5382623071 AS datetime) as human_time; -- or SELECT CAST(GETDATE() AS float) as float_time;
But without milliseconds yet
Usage
Float to DateTime
$converter = new MSSQLTimeConverter(); $MSDateTime = 43243.5382623071; $humanDate = $converter->floatToDateTime($MSDateTime, 'Europe/Kiev'); echo $humanDate->format('Y-m-d H:i:s.u'); // 2018-05-25 12:55:05.000000
DateTime to Float
$timeNow = new DateTime('2018-05-25 12:55:05.000000', 'Europe/Kiev'); $converter = new MSSQLTimeConverter(); echo $converter->dateTimeToFloat($timeNow); // ~43243.5382623071
If you want to convert only time
$time = "12:55:05"; // You need to hardcore 1900-01-01. I hope it's temporary. $dateTime = new DateTime("1900-01-01 " . $time, 'Europe/Kiev'); $converter = new MSSQLTimeConverter(); echo $converter->dateTimeToFloat($timeNow); // ~43243.5382623071
TODO
- take with milliseconds