Results 1 to 7 of 7

Thread: write date in custom field (PHP)

  1. #1
    Benjamin C. B. is offline Sugar Community Member
    Join Date
    Jul 2011
    Posts
    39

    Default write date in custom field (PHP)

    Hi,

    I need to create/update some leads with date values that are stored in custom fields.
    Here is how I try to do it :

    PHP Code:
    <?php
    if(!defined('sugarEntry'))define('sugarEntry'true);
    require_once(
    'include/entryPoint.php');
    require_once 
    'modules/Leads/Lead.php';


    $lead=new Lead();
    $lead->birth_date_c=date('Y-m-d H:i:s'strtotime('12/31/1976'));
    echo 
    'before :'.$lead->birth_date_c."<br>\n";
    $lead->save();
    echo 
    'after :'.$lead->birth_date_c;
    ?>
    But id doesn't work. I get this :
    Code:
    before :1976-12-31 00:00:00
    after :
    and in SugarCRM, the lead is created with 2000-01-01 in the birth_date_c field.

    Can someone tell me what's wrong with this code ?
    thanks !

  2. #2
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Posts
    977

    Default Re: write date in custom field (PHP)

    How did you define the custom field "birth_date_c" in Studio? Or did you want to set the value of the standard field "birthdate"?
    Stefan Ulrich Sauer
    System Analyst

    Devoteam Danet GmbH
    Gutenbergstraße 10
    D-64331 Weiterstadt
    Germany
    email: Stefan-Ulrich.Sauer@devoteam.com
    http://www.devoteam.de

  3. #3
    Benjamin C. B. is offline Sugar Community Member
    Join Date
    Jul 2011
    Posts
    39

    Default Re: write date in custom field (PHP)

    The dirth_date_c is a Date field, created in the studio.
    And I can't find in the Studio the standard birthdate field...

  4. #4
    Angel's Avatar
    Angel is offline Sugar Community Member
    Join Date
    Jul 2005
    Location
    Los Angeles
    Posts
    4,811

    Default Re: write date in custom field (PHP)

    I was thinking the same, is it defined as a DATE field or DATETIME field? If the former, that would explain the problem as you should only pass the date part in that case.

    Also, the 'AFTER' line in your debug process is fine, as it happens after the record is saved to the Leads module, thus, the record is no longer loaded.
    Regards,

    Angel Magaña
    Co-Author: Implementing SugarCRM 5.x (Packt Publishing -- Sept. 2010)
    Blog: http://cheleguanaco.blogspot.com.
    Twitter: @cheleguanaco.

    ________
    | Projects: |_____________________________________
    |
    | CandyWrapper (.NET Wrapper for SugarCRM SOAP API). Source now available on GitHub!
    | GoldMine to SugarCRM Express Conversion. Latest: 1.0.1.7 (Nov. 3, 2009)
    | CRM SkyDialer (Skype Integration). Latest: 1.0.2 (Feb. 17, 2010)
    | Round Robin Leads Assignment
    | Phone Number Formatter
    | CaseTwit (Twitter Integration)
    ______________________________________________

  5. #5
    Benjamin C. B. is offline Sugar Community Member
    Join Date
    Jul 2011
    Posts
    39

    Default Re: write date in custom field (PHP)

    In the database, it's a DATETIME column. But in SugarCRM it's called a DATE field (since DATETIME is not a field type in SugarCRM).
    Still, I tried to replace :
    $lead->birth_date_c=date('Y-m-d H:i:s', strtotime('12/31/1976'));
    by
    $lead->birth_date_c=date('Y-m-d', strtotime('12/31/1976'));

    and it doesn't work either.
    By the way, I have many custom DATE fields in SugarCRM, some with a column DATE in the database, others with ta column DATETIME. How come they don't have the same column type ?

    Thanks for your help !

  6. #6
    Benjamin C. B. is offline Sugar Community Member
    Join Date
    Jul 2011
    Posts
    39

    Default Re: write date in custom field (PHP)

    Can nobody help me ?

  7. #7
    ldd-silver-ziegler is offline Sugar Community Member
    Join Date
    Aug 2011
    Location
    Voecklabruck/Austria
    Posts
    55

    Default Re: write date in custom field (PHP)

    use the sugar timedate object for this.

    e.g.

    PHP Code:
    global $timedate;
    $timestamp=time();
    $formatted_date_time=date($timedate->get_date_time_format(), $timestamp); 

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 2009-11-10, 06:58 AM
  2. Logic Hook + Passing Date to Custom Date Field
    By chrislynch8 in forum Developer Help
    Replies: 12
    Last Post: 2009-07-22, 03:58 PM
  3. custom date field default to none
    By sidh211 in forum Help
    Replies: 0
    Last Post: 2008-06-02, 12:28 PM
  4. custom field -> dateTIME not just date
    By elRey in forum Developer Help
    Replies: 6
    Last Post: 2006-11-20, 10:06 PM
  5. Replies: 1
    Last Post: 2006-06-16, 03:35 AM

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
  •