0

I have a date string what I would like to convert in digits. The string looks like

Dienstag, 30. Oktober 2012

and the code what I've been trying to use

date('Y.m.d' , strtotime($str[4]));

returns every time 1970.01.01

4 Answers 4

2

You can make this by changing the current locale set http://php.net/manual/bg/function.setlocale.php If you know the source date format you can also stick to using https://www.php.net/date_create_from_format

Here is more details regarding the same question strtotime With Different Languages?

Sign up to request clarification or add additional context in comments.

Comments

1

strtotime takes string in English language. Look at possible date/time formats

1 Comment

thanks for the feedback. could I use setlocale(LC_TIME, "de_DE")? to get my string converted
0

use strtotime() to convert the date into timestamp

$ts = strtotime('21 december 2007'); echo date('Y-m-d', $ts);

Comments

0
<?php
setlocale(LC_ALL, 'fr_FR');
$str= 'Dienstag, 30. Oktober 2012';

echo date('Y.m.d' , strtotime($str[4]));   
?>

4 Comments

Why are you using a French locale when the date is in German?
<?php setlocale(LC_ALL, 'de_DE'); $str= 'Dienstag, 30. Oktober 2012'; echo date('Y.m.d' , strtotime($str[4])); ?> //2012.11.28// check this
and what return str[4] for you?
why don u echo n check the output??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.