Pregunta

I am receiving the following value from a database which is a millsecond (microtime) value

1369057622.4679

I would like to output this in PHP to be

3 Day's ago

Essentially reading the milliseconds value and converting it to a relative date string, can anyone suggest an easy method to do this.

¿Fue útil?

Solución

You may do the following:

$input = 1369057622.4679;

$diff = floor(($input-time())/86400); // calculating the difference

$result = abs($diff) . (abs($diff)==1 ? ' day ':' days ') . ($diff<=0 ? 'ago':'ahead'); // making the result.
echo $result; // output: 1 day ago
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top