Results 1 to 7 of 7

Thread: Calulating time difference when I view a custom record

  1. #1
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Calulating time difference when I view a custom record

    Hi,

    I am creating a new custom module. It will be used to keep track of server we have in a DC and what Clients are using them. I have an online date and the offline date should be 4 weeks later. I want a field "Weeks Online" that will show the number of weeks it has been online for.

    How can I calulated this without editing the record. I have both dates filled in and only what to show the difference in the detail view. So a user clicks on the record and the "Weeks Online" field is updated?

    Is there a logic hook that will execute when I click on the detail view or will a custom view.detail.php be required?

    Rgds
    Chris
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  2. #2
    kbrill's Avatar
    kbrill is offline SugarCRM PS Engineer
    Join Date
    Jul 2004
    Location
    St Louis, MO
    Posts
    3,183

    Default Re: Calulating time difference when I view a custom record

    We need to know what version of SugarCRM you are running, CE or PRO/ENT
    Kenneth Brill - Help Forum Moderator

    I do not respond to 'Private Messages'. Please email me directly instead

    When asking for help, PLEASE give us your Server Information and Version Numbers as asked for on the 'Post New Message' screen as well as any JavaScript errors shown at the bottom of the browser window.
    Help us Help You

  3. #3
    sugarcane is offline Sugar Community Member
    Join Date
    Apr 2005
    Location
    Chicago, IL
    Posts
    1,207

    Default Re: Calulating time difference when I view a custom record

    Based on what you are describing I would go with a custom view.detail.php and then push a value into the detailview metadata file.
    Intelestream has a great deal of experience hosting and customizing the SugarCRM application. Our company is made up by former employees of SugarCRM, and together we have over 50 years of experience working with the application. To learn more about us, please visit our website at www.intelestream.net or contact us directly at 800-391-4055 or by email at info@intelestream.net

  4. #4
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Re: Calulating time difference when I view a custom record

    Quote Originally Posted by kbrill View Post
    We need to know what version of SugarCRM you are running, CE or PRO/ENT
    Hi Ken,

    I'm running 5.2.0k Pr.

    Rgds
    Chris
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  5. #5
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Re: Calulating time difference when I view a custom record

    So I created a custom view.detail.php and I have code it that worked perfectly when testing in a logic hook. I getting the week number of one date and now and calulating the number of weeks from that..

    PHP Code:
    if(!empty($this->bean->fdc_date_online_one))
    {
    $week_online date("W",strtotime($this->bean->fdc_date_online_one));
    $week_now date("W",time());
    if(
    $week_now $week_online)
    {
    $weeks_online = ((52 $week_online) + $week_now);
    $this->bean->fdc_weeks_online_c $weeks_onine;
    }
    $weeks_online $week_now-  $week_online;
    $this->bean->fdc_weeks_online_c $weeks_onine
    When the had the above code in a Logic Code it was giving me the Week Number of fdc_date_online_one. But in the detail view it is returning 01 for any date but it is returning the correct weel number of $week_now..

    Any ideas of why this is happening?

    Rgds
    Chris
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  6. #6
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Re: Calulating time difference when I view a custom record

    Have it working but I would like some feed back on the way the dates are handle using the bean

    I was getting my date field using $this->bean->fdc_date_online_one. This would return 14/04/2010. I was then trying to get the Week Number from that using date("W",strtomtime($this->bean->fdc_date_online_one)) this always returned 01 because the date function was seeing my dated as 1970-01-01

    I had to query the database to get the fdc_date_online_one value which would return 2010-04-14, I then used date("W",strtotime($row['fdc_date_online_one'])) and this returned the correct Week Number

    Is there a way I can use the bean to get the date in the format it is in the Database? It would see to be more efficient than having to query the database everytime I want to pull out a date value?

    Thing is that when I used a Logic Hook the Bean method returned the correct date?


    In a Logic Hook $bean->fdc_date_online_one returns the date in the DB Format Y-m-d
    In the Detail View $this->bean->fdc_date_online_one return the date in the users date format d/m/Y

    Rgds
    Chris
    Last edited by chrislynch8; 2010-04-28 at 11:17 AM.
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  7. #7
    Join Date
    Jul 2010
    Posts
    8

    Post Re: Calulating time difference when I view a custom record

    hi can anyone help me in calculating date difference in week .... between current date and date created .....

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Time difference between CRM and DB
    By chrislynch8 in forum Help
    Replies: 9
    Last Post: 2010-04-14, 06:56 PM
  2. Time difference issue.
    By marketadvantage in forum Developer Help
    Replies: 1
    Last Post: 2009-12-22, 06:41 PM
  3. Replies: 0
    Last Post: 2008-10-23, 05:58 PM
  4. Replies: 1
    Last Post: 2008-05-19, 01:44 PM
  5. Replies: 7
    Last Post: 2005-09-13, 11:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •