A
A
Alexander Lashchevsky2016-05-02 19:59:52
PHP
Alexander Lashchevsky, 2016-05-02 19:59:52

How to convert custom date format to DATE format?

There is a date column in the database , it contains the date in DATE format, for example 2016-05-02
In PHP, you need to display this date in a human-readable form - - and we get But the difficulty for me is different: how to do the opposite, i. convert $date to DATE format? In other words, the user specifies the date in the input in the format dd.mm.yyyy (the input format is strictly only this, it will not indicate otherwise), and it must be sent to the database in the standard format. $date = date("d.m.Y", strtotime($row['date']);$date == 02.05.2016

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Inishev, 2016-05-02
@Alexanevsky

php.net/manual/en/datetime.createfromformat.php

$date = DateTime::createFromFormat('d.m.Y', $_POST['date']);
$stringForSql = $date->format('Y-m-d');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question