How to convert date to datetime in PHP?
This post converting the Date format to DateTime format with beginning and end of that day in php.
1. Code:
<?php function convertDateToDateTime($str, $isFirstDay = true){ if (!is_null($str) && trim($str) != '' && strlen($str) <= 10) { $str .= $isFirstDay ? " 00:00:00" : " 23:59:59"; } return $str; } $str = "20/06/2022"; echo(convertDateToDateTime($str, false)); ?>
2. Example:
Input:
$str = "20/06/2022"; convertDateToDateTime($str, false); convertDateToDateTime($str, true)
Output:
20/06/2022 23:59:59 20/06/2022 00:00:00