Date format in diary script

Hi i have had a website done for me its a diary script.

it shows the date as for example 2021-09-10

the code bit that shows this is

{{$dairy->date_time}}

how do change this to show 10-09-2021 or even Friday 10th Sept 2021

thanks

Well, that is sort of a loaded question… It really depends on what the results of your object is.
What that means is that you are using some sort of template or word-press site. The {} shows us that.

Well, first if the output of $dairy->date_time is a time-formatted data you can just use this type of code to display it…

date_format($dairy->date_time, "d-m-Y H:i:s")
OR without the time:
date_format($dairy->date_time, "d-m-Y")

BUT, if the data is a string, you would have to use the PHP function to turn it into a date object.
Something like this:

$date = date_create("2013-03-15");
echo date_format($date, "d-m-Y");
OR
$date = date_create($dairy->date_time);
echo date_format($date, "d-m-Y");

There are hundreds of combinations of date formats. Here is a link listing most of them: Date-Formats

thank you for your advice

You are very welcome!

Oh, also, if it is a string, you can convert it to a date format with the PHP stringtotime fucntion…

Sponsor our Newsletter | Privacy Policy | Terms of Service