0

I need to convert date written in the natural language to timestamp or any other standard date format. Dates are in four languages: English, German, French, and Spanish. I can convert all except Spanish date with Intl extension.

Example of date in natural languages:

// es - 19 de julio de 2017
// fr - 2 février 2018
// en - May 16, 2016
// de - 27 Juni 2018

French date parse works fine

$df = \IntlDateFormatter::create(
    'fr_FR',
    \IntlDateFormatter::MEDIUM,
    \IntlDateFormatter::NONE,
    'Europe/Kiev'
);

$timestamp = $df->parse('2 fevrier 2018'); // 1517518800

But Spanish, return false

$df = \IntlDateFormatter::create(
    'es_ES',
    \IntlDateFormatter::MEDIUM,
    \IntlDateFormatter::NONE,
    'Europe/Kiev'
);

$timestamp = $df->parse('19 de julio de 2017'); // false

What do I do wrong?

Serhii Popov
  • 3,326
  • 2
  • 25
  • 36

1 Answers1

0

You shouldn't have used de in your date.

$timestamp = $df->parse('19 julio 2017'); // false
echo $timestamp;

output is

1500411600

will work perfectly.

MrSmile
  • 1,217
  • 2
  • 12
  • 20
  • Yes, it works but I get a date from Amazon and in the future, we will work with all Amazon marketplaces and it will be good parse a date without preparation. – Serhii Popov Jul 13 '18 at 08:26