Is there a way to add a line break
in PHP date formats?
I am using a plugin for WordPress which allows for the use of regular PHP date formats and have tried numerous options but not gotten something to work yet.
What I have tried:
</br>
j MThanks!
Change YYYY-MM-DD to DD-MM-YYYY In the below example, we have date 2019-09-15 in YYYY-MM-DD format, and we will convert this to 15-09-2019 in DD-MM-YYYY format. $orgDate = "2019-09-15"; $newDate = date("d-m-Y", strtotime($orgDate)); echo "New date format is: ".
You can simply use the PHP date() function to get the current data and time in various format, for example, date('d-m-y h:i:s') , date('d/m/y H:i:s') , and so on.
echo date("l<\b\\r>j M");
or
echo date('l<\b\r>j M');
Outputs:
Wednesday<br>2 Jan
You need to escape the HTML tag to avoid it being parsed as date segments:
<?php
echo date('l \<\/\b\r\> j M');
?>
Alternatively, if you don’t like the above (like me), then you can use the strftime() function:
<?php
echo strftime('%A<br />%e %b');
?>
The second parameters of both the date()
and strftime()
functions takes a timestamp.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With