0

I am using timestamps and need to print the date in the format 03d 01h 10m. I could not do it using the date() formatting. How can I do it so that after the days I have a d, after the hours m, and after the minutes m?

lonesomeday
  • 233,373
  • 50
  • 316
  • 318
Mythriel
  • 1,360
  • 5
  • 24
  • 45

4 Answers4

3

Just escape the literal characters you want with a backslash:

date('\h\e\l\l\o'); // just echoes hello

If you escape a character that didn't need escaping, it doesn't matter - nothing bad worth noting happens.

Joe
  • 15,669
  • 4
  • 48
  • 83
3

Manual: Example #2 Escaping characters in date():

<?php
// prints something like: Wednesday the 15th
echo date('l \t\h\e jS');
?>
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
2

Like this: echo date ("d\d. H\h. i\m.");

Aidas
  • 1,213
  • 2
  • 10
  • 16
1

Try using the DateTime class' diff method. See the examples over on php.net.

Oldskool
  • 34,211
  • 7
  • 53
  • 66