Answer the question
In order to leave comments, you need to log in
How to correctly format the date in php?
Confused with dates - a hell of a mixture of formats ... php, moment.js datetimepickera and entering into the database ... I
form on the client - jquery and moment.js
formatD_T = 'D MMMM GGGG в HH:mm'; // выводит 3 августа 2015 в 13:00
или
formatD_T= formatD ="D MMMM GGGG"; // выводит 3 августа 2015
var newDate = moment(date).format(formatD_T);
$data['event_start']=date("Y-m-d H:i:s", strtotime($data['event_start']));
$datetime = new DateTime($data['event_start']);
$datetime->createFromFormat('d M Y', $data['event_start']); // формат вроде верный, по документации смотрел
print_r ($datetime);
3 августа 2015string<br />
<b>Fatal error</b>: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (3 августа 2015) at position 0 (3): Unexpected character' in C:\xampp\htdocs\ac_new\admin\mod_calendar\handler_calendar_new1508.php:25
Stack trace:
$date = DateTime::createFromFormat('d M Y', '15 February 2009');
echo $date->format('Y-m-d');
Answer the question
In order to leave comments, you need to log in
If the deadline is yesterday:
$months = ['April' => 'Апреля', 'June' => 'Июня', ... ];
$date_string = '15 Апреля 2009';
$date_string = str_ireplace(
array_values($months),
array_keys($months),
$date_string
);
$date = DateTime::createFromFormat('d M Y', $date_string);
echo $date->format('Y-m-d');
To stop irritating yourself, just store and send the date everywhere in unix timestamp, and format it already at the output.
You must use the ISO 8601 format
In PHP, this is done via $datetime->format('c'); or $datetime->format(DateTime::ISO8601)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question