If I have a string of the following:
"2013-10-28"
and when I convert to a DateTime
using the following function:
new \DateTime("2013-10-28");
it always gives me a DateTime
with the time not set.
I want to have two DateTime :
DateTime
which is on the same date but at the end of the day 23:59:59.How do I do this given the string above?
We can convert a string to datetime using strptime() function. This function is available in datetime and time modules to parse a string to datetime and time objects respectively.
strptime() is another method available in DateTime which is used to format the time stamp which is in string format to date-time object.
Use DateTime::setTime
$d = new \DateTime("2013-10-28");
$d->setTime(23, 59, 59);
Have a look at all possible compound formats.
The MySQL format should be the easiest for your use case:
new \DateTime("2013-10-28 00:00:00");
new \DateTime("2013-10-28 23:59:59");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With