Answer the question
In order to leave comments, you need to log in
How not to waste time when changing format in DateTime?
Good morning, the problem I have is this, there is a field
<input type="datetime-local" name="deadlines" value="2017-06-01T08:30">
$date = new \DateTime($deadlines);
$deadlines = $date->format('U')); // это сохраняю в бд
$date = new \DateTime('@' . $task['deadlines']);
$task['deadlines'] = $date->format('Y-m-d\T\0G:30');
$task['deadlines']
$date = new \DateTime($deadlines);
echo 'Пришло: ' . $deadlines . '<br />';
if ($deadlines = $date->format('U')) {
echo 'Конвертировали в : ' . $deadlines . '<br />';
Task::create($message, $deadlines, $importance, $id_project);
}
echo 'приняли:' . $deadlines . '<br/>';
$date = new \DateTime('@' . $deadlines);
echo 'Изменим в формат в котором будем выводить в будущем: ' . $date->format('Y-m-d\TH:i');
Answer the question
In order to leave comments, you need to log in
Solution: instead
of prescribing
$date = new \DateTime();
$date->setTimestamp($deadlines);
How much time has been spent on such questions, but the solution is simple: store dates in the database in a bigint (64-bit) field in the Unix timestamp format. And in the application, bring to the desired time zone. And no problems, regardless of the database server configuration.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question