Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add <br> tag in PHP Date format

Tags:

php

datetime

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:

  • l </br> j M
  • l \n j M

Thanks!

like image 887
SixfootJames Avatar asked Jan 02 '13 12:01

SixfootJames


People also ask

How can I change the date format in PHP?

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: ".

How to get date with PHP?

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.


2 Answers

echo date("l<\b\\r>j M");

or

echo date('l<\b\r>j M');

Outputs:

Wednesday<br>2 Jan
like image 110
Wojciech Zylinski Avatar answered Oct 18 '22 06:10

Wojciech Zylinski


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.

like image 39
Martin Bean Avatar answered Oct 18 '22 04:10

Martin Bean