6

I need to print result of function date('d-m-y H:i:s', $time) on two lines like this:

26-11-2019 
10:00:02

I try to add <br/> between 'd-m-y' AND 'H:i:s' doesn't help.

mdBender
  • 369
  • 2
  • 8

3 Answers3

3

Try this:

echo nl2br(date("d-m-y\nH:i:s", $time));

Note that I used double quotes instead of single quotes. This is because \n won't work with single quotes. For your reference: https://www.php.net/manual/en/function.nl2br.php What is the difference between single-quoted and double-quoted strings in PHP?

Arsi
  • 176
  • 11
1

You can use simple PHP date function with escape sequences <\b\r>

echo date('d-m-y <\b\r>H:i:s');

Output

27-11-19

00:45:55

Referance: How to add <br> tag in PHP Date format

Ankur Tiwari
  • 2,762
  • 2
  • 23
  • 40
0

Try like this may it will help.

!DOCTYPE html>
<html>
<body>

<?php 
     echo date('d-m-y', $time) . "<br>" . date('H:i:s', $time) 
?>

</body>
<html>
Valor_
  • 3,461
  • 9
  • 60
  • 109
supriya suresh g
  • 385
  • 1
  • 2
  • 13