Date calculation question
3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 15, 2014 (RSS)
By Jesus - July 12, 2014 - edited: July 12, 2014
Hello everyone,
I've a table inside my CMSBuilder system which contains a date field (2014-01-01).
I've 70 records on my table and I need to know how long since that day until today (Obviously today its a dynamic value).
The results (per record) for that dynamic calculation field needs to be something like: 3 years, 2 months, 14 days
Is this possible? Will someone point me to a place for a similar situation or provide me some help in order to accomplish this? At this point I'm working just on my backend but we can create a report page if need it to complete this operation.
Thanks in advance for the help!
Jesus
By Jesus - July 12, 2014
I found this code while searching on the internet, is this useful?
function transcurido($time) {
$transcurido = time()-$time;
$tc['minutos'] = @$transcurido/60;
$tc['horas'] = @$transcurido/3600;
$tc['dias'] = @$transcurido/86400;
$tc['meses'] = @$transcurido/'2629743,83';
$tc['años'] = @$transcurido/31556926;
$plu['minutos'] = (intval($tc['minutos'])==1) ? NULL : 's';
$plu['horas'] = (intval($tc['horas'])==1) ? NULL : 's';
$plu['dias'] = (intval($tc['dias'])==1) ? NULL : 's';
$plu['meses'] = (intval($tc['meses'])==1) ? NULL : 's';
$plu['años'] = (intval($tc['años'])==1) ? NULL : 's';
$frase = ($transcurido<60 AND $transcurido>15) ? 'menos de un minuto' : $frase;
$frase = ($transcurido>60 AND $transcurido<3600) ? intval($tc['minutos']).' minuto'.$plu['minutos'] : $frase;
$frase = ($transcurido>3600 AND $transcurido<86400) ? intval($tc['horas']).' hora'.$plu['horas'] : $frase;
$frase = ($transcurido>86000 AND $transcurido<'2629743,83') ? intval($tc['dias']).' dia'.$plu['dias'] : $frase;
$frase = ($transcurido>'2629743,83' AND $transcurido<31556926) ? intval($tc['meses']).' mese'.$plu['meses'] : $frase;
$frase = ($transcurido>31556926 AND $transcurido<315569260) ? intval($tc['años']).' año'.$plu['años'] : $frase;
$frase = ($transcurido>3155692600) ? 'mas de 10 años' : $frase;
return $frase;
}
<?php
echo 'Miembro desde '.transcurido($fecha);
?>
<?php
$fecha = '1257954093';
?>
I hope anyone could give a hand or is there's an easier way to create this share the solution with me :)
Thanks!
By Damon - July 15, 2014
Hi,
Take a look at this function Chris wrote for Facebook-style relative times (e.g. "7 hours ago"):
http://www.interactivetools.com/forum/forum-posts.php?postNum=2208966#post2208966
....it turns a date into a more human-readable format such as "37 seconds ago", "about an hour ago", "Wednesday at 6:07pm", or "February 17, 2007", depending on how far in the past the date is. It doesn't handle future-dates at all.
This could be a starting point.
We can also write up the custom code needed through our consulting department if needed. Send in a email to consulting@interactivetools.com.
Thanks!
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/