krzysztofzylka / date
Date library
1.0.1
2024-02-03 16:13 UTC
Requires
- php: >=8.0
README
composer require krzysztofzylka/date
Create instance
$date = new \Krzysztofzylka\Date\Date();
Static methods
Get simple date
\Krzysztofzylka\Date\Date::getSimpleDate() \Krzysztofzylka\Date\Date::getSimpleDate(true) //with microseconds
Get seconds to date
\Krzysztofzylka\Date\Date::getSecondsToDate($seconds)
Create instance
\Krzysztofzylka\Date\Date::create(null) \Krzysztofzylka\Date\Date::create(time()) \Krzysztofzylka\Date\Date::create(date('Y-m-d H:i:s'))
Method
Get time
$date->getTime()
Get date
$date->getDate()
Set date
$date->set(null) $date->set(time()) $date->set(date('Y-m-d H:i:s'))
Change default format (Y-m-d H:i:s)
$date->format($format)
Add second to date
$date->addSecond($seconds)
Add minute to date
$date->addMinute($minutes)
Add hours to date
$date->addHour($hours)
Add day to date
$date->addDay($days)
Add month to date
$date->addMonth($months, $fixCalculate)
Example
$date = new \Krzysztofzylka\Date\Date('2024-03-31'); $date->addMonth(1); echo $date->getDate('Y-m-d'); //2024-04-30 $date = new \Krzysztofzylka\Date\Date('2024-03-31', false); $date->addMonth(1); echo $date->getDate('Y-m-d'); //2024-05-01
Add year to date
$date->addYear($years)
Subtract second from date
$date->subSecond($seconds)
Subtract minute from date
$date->subMinute($minutes)
Subtract hours from date
$date->subHour($hours)
Subtract day from date
$date->subDay($days)
Subtract month from date
$date->subMonth($months)
Subtract year from date
$date->subYear($years)
Utils
Get date month difference
\Krzysztofzylka\Date\DateUtils::dateMonthDifference($dateFrom, $dateTo)