I want to store a timestamp in the database with time component as 00:00:00
.
The following code:
$start_date = Carbon::createFromFormat('d-m-Y', $date_interval["start_date"]);
$end_date = Carbon::createFromFormat('d-m-Y', $date_interval["end_date"]);
adds the current time to the date, when I provide a date only without time specification.
I need this because I need to retrieve the internal integer from the database afterwards which should be the start of the day.
What is the best way to store this 'start of day'?
0
or an empty datetime like0000-00-00 00:00:00
? – Perceptyyyy-mm-dd 00:00:00
. – AdiCarbon::createFromFormat('d-m-Y 00:00:00', ..);
;p – RovitstartOfDay()
method that you can use to reset the date objects time to00:00:00
, once again in docs Ctrl-F with help you find it. – RovitCarbon::createFromFormat('d-m-Y', $date_interval["start_date"])->startofDay()
works. If you provide it as an answer, I will accept it. – AdiAn important difference is that DATETIME represents a date (as found in a calendar) and a time (as can be observed on a wall clock), while TIMESTAMP represents a well defined point in time.
-> https://mcmap.net/q/40410/-should-i-use-the-datetime-or-timestamp-data-type-in-mysql – Aditimestamp
mysql type if the purpose is scheduling recurrent events. mysql will convert timestamp values from local time to UTC implicitly. Read these docs carefully. Next, you should realize that scheduling future events, especially recurring ones, is a complex subject. My answer here may help you. – Naevus