0

i've the following code

The date format in the database is (yyyy.mm.dd) so I want to convert/format it to (dd.mm.yyyy)

This code is reading the date from the database

                    {
                      echo '<span class="badge badge-success" style="background-color:red;">Nicht Verf&uuml;gbar</span> <p><i class="fas fa-info-circle" aria-hidden="true" style="color:Red;"></i> Vergeben bis :<span style="color:red;font-weight:600;">';
                      echo htmlentities($result->VerfuegbarAb);
                      echo '</span></p>';
                    }

My question, how I can get this into my code? I don't know how to add a time format into this code and yes this code looks like horrible and would be a better solution but i'm learning still php and i'm going trough everything to get better :) Hope someone can help me would be amazing. Thanks in advance

2 Answers 2

2

You can just do

$newLocale = setlocale(LC_TIME, 'de_DE', 'de_DE.UTF-8');
$formatted_date = strftime('%d. %B %Y',$result->VerfuegbarAb);

For this to work, the locale 'de_DE' needs to be installed on your system.

P.S: Kudos to you for using htmlentities() as a beginner after fetching data from the database. It's a great habit and often forgotten.

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

Comments

1

This works for me:

echo date( 'd.m.Y', strtotime('2020-05-03'));

OR:

$testdate = '2020.05.03';

echo date( 'd.m.Y', strtotime(str_replace('.','-',$testdate)));

In your case:

echo date( 'd.m.Y', strtotime(str_replace('.','-',$result->VerfuegbarAb)));

Comments

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.