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
?
Asked
Active
Viewed 291 times
0

lonesomeday
- 233,373
- 50
- 316
- 318

Mythriel
- 1,360
- 5
- 24
- 45
-
2What have you done so far? Post the code that you've tried. – Tango Bravo Feb 20 '12 at 13:36
4 Answers
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
1
Try using the DateTime class' diff
method. See the examples over on php.net.

Oldskool
- 34,211
- 7
- 53
- 66