-3

I have this data | 01 Oktober 2017 |

This is an Indonesian date

And i want to convert into dateformat. And so the result must be 2017-10-01. Can you please help ?

2 Answers2

0

You need to convert dates with the month name in Indonesian into PHP readable date formats.

function getDate($indonesianMonthName){

  setlocale(LC_ALL, 'en_US');

  $month_numbers = range(1,12);

  foreach($month_numbers as $month)
    $english_months[] = strftime('%B',mktime(0,0,0,$month,1,2011));

  setlocale(LC_ALL, 'Indonesian');

  foreach($month_numbers as $month)
    $indonesian_months[] = strftime('%B',mktime(0,0,0,$month,1,2011));

  return str_replace($indonesian_months, $english_months, $indonesianMonthName);

}

echo getDate('01 Desember 2017');
echo getDate('01 Oktober 2017');

So basically, you create an array of every single month and its corresponding value in English and Indonesian, and then you use str_replace() to "translate" the date into English.

You can now use regulat strtotime() and Date() functions on the returned string.

References : https://stackoverflow.com/a/39874682/6124528

Manav
  • 1,357
  • 10
  • 17
-1

Use strtotime,

$date = strtotime($_POST['fixtureDate']);
    $fixtureDate = date("Y-m-j", $date);

You can then play with the format so that it displays how you want it to

Sean Konig
  • 124
  • 1
  • 12
  • A comment should have worked perfectly + link-only answers are evil. Imagine once the target page gets deleted, so you will have a dead link. Put the essential part of the target page into your answer. Whit such answer you are decreasing the quality of SO – B001ᛦ Oct 06 '17 at 09:22
  • this is an indonesian date, in datepicker, language set it to (id). i use strtotime it gives me result 1970-01-01. and this is wrong – Sandhi Zukhruf Oct 06 '17 at 09:35
  • hey, you need to update the format "Y-m-j". Have a look here http://php.net/manual/en/function.date.php – Sean Konig Oct 06 '17 at 09:38
  • The date is in Indonesian, you cannot merely `strtotime()` it. – Manav Oct 06 '17 at 09:41