1

i want to convert a date format to another using php 6th of November 2017 to 2017-11-6

i tried

$newDate = date("Y-m-d", strtotime('6th of November 2017'));

but it always returns 01-01-1970

shanechiu
  • 85
  • 3
  • 12
Uday Kumar
  • 121
  • 1
  • 10

3 Answers3

4

When you create date from specific format then use createFromFormat of date.

$date = DateTime::createFromFormat('jS \o\f F Y', '6th of November 2017');
echo $date->format('Y-m-d');

Note: If you have string in your format then you have to escape that string (with \) for conversation

DEMO

B. Desai
  • 16,414
  • 5
  • 26
  • 47
0

Try this:

$newDate = date("Y-m-d", strtotime("6 November 2017"));

B. Desai
  • 16,414
  • 5
  • 26
  • 47
Ashish Tiwari
  • 1,919
  • 1
  • 14
  • 26
0

Replace 6th of to 6th and it will be fine..

$newDate = date("Y-m-d", strtotime('6th November 2017'));
echo ($newDate);

result

2017-11-06
Arbaz Khan
  • 80
  • 8