SOLVED: Days difference between today and creation date.

Idea created by arturo.hernandez on Oct 29, 2015
    Active
    Score15
    • arturo.hernandez
    • Surabhil Sergy
    • Ishani Lad
    Hi everybody, 

    A couple days ago I had this problem, today it's fixed using Logic Hooks. This is the code.

    logic_hooks.php:

    <?php
        $hook_version = 1;
        $hook_array = Array();
        $hook_array['after_retrieve'] = Array();
        $hook_array['after_retrieve'][] = Array(
            //Processing index. For sorting the array.
            1,
           
            //Label. A string value to identify the hook.
            'calculate',
           
            //The PHP file where your class is located.
            'custom/modules/Accounts/logic_hooks_class.php',
           
            //The class the method is in.
            'logic_hooks_class',
           
            //The method to call.       
            'after_retrieve_DaysOld'
        );

    ?>


    logic_hooks_class.php:

    <?php

        if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
       
        class logic_hooks_class
        {

        function after_retrieve_DaysOld($bean, $event, $arguments)       
        {
         
            $now = time(); // or your date as well 
            $diff = ($now - strtotime($bean->date_entered))/(60*60*24);
            $bean->total_days_old_c = $diff;
       
          }
    }

    ?>

    If you have any questions please feel confident to contact me.

    Regards!!