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
  • 224,675
  • 49
  • 309
  • 312
Mythriel
  • 1,342
  • 5
  • 23
  • 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,441
  • 4
  • 43
  • 81
3

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

<?php
// prints something like: Wednesday the 15th
echo date('l \t\h\e jS');
?>
CodeCaster
  • 139,522
  • 20
  • 204
  • 252
2

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

Aidas
  • 1,183
  • 2
  • 8
  • 15
1

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

Oldskool
  • 33,525
  • 7
  • 51
  • 64