Skip to content
Advertisement

create DateTime string for the beginning and the end of the day

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 :

  • one marking the beginning of the day, meaning at 00:00:00
  • another 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?

Advertisement

Answer

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");
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement