How can i auto calculate work exprience in suitecrm?

I have a candidate module. In that module i have 2 date field From and To. Using these two fields i want to calculate difference between these two date in my other duration field.

I can give you a very similar example here

https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/15154-is-there-logic-hook-for-detailsview#50990

It is an extension of the Contact’s Detail View, which makes an age calculation from a date, and shows it on the view.

You’ll have to adapt this to handle your date difference, and to make it for a custom module. Good luck.

i got following error:-

Parse error: syntax error, unexpected ‘portal_on’ (T_STRING), expecting ‘]’ in /home/connexon/public_html/suitecrmAdmin/custom/modules/AOS_Products/views/view.detail.php on line 45

Hi @sneha ashtekar,

Are you looking to calculate the different between the dates? Also, are you including things like weekends?

If this is the case, I can happily post some sample code that can work our the difference between 2 dates.

Thanks,
Ellis.

Please help me with other code

Okay, there are a couple ways to do it.

You can use the ‘diff’ function that the DateTime object deals with nicely in php, this example is:

$duration = $start_date->diff($end_date);

This will return an array which will store weeks, days, hours, minutes etc.

On way to get the days could be:

$days = $duration->d;

However you maybe have days, hours and minutes, or weeks. so you could do something like:


if ($duration->d != 0) {
            $days = $duration->d;
        }// End if

        if ($duration->h != 0) {
            $hours = $duration->h;
        }// End if

        if ($duration->i != 0) {
            $minutes = $duration->i;
        }// End if

You could use something different to if statements if you like.

This will calculate the difference and presume that you count all days, you can use things like business hours to only count by your crms working times, or i could point you towards how to remove weekends if you like.

Please let us know how you get on.

Thanks,
Ellis.

1 Like

This is showing me error for calculate diff().

Could you copy in the error please? And possibly show how you are using the function?

Thanks,
Ellis.

Hi,

I just read your message again and although I do not know which error you are getting, I have a guess that it may be due to the fact that the diff() uses DateTime objects and not just a Date object or string, one thing that you could try is:

$date_time_1 = new DateTime($date_1);

Then use your new DateTime objects on both parts of the diff() operator. If it is just a date you are doing you can set the time of the date time function using

$date_time_1->setTime('your desired hour','your desired minute','your desired  seconds')

Hope this helps,
Ellis.