You need to sign in to do that
Don't have an account?
Remedial PHP/SF Question on sending dateTime values
I'm a DBA who has been stuck with completing some PHP code that interacts with Salesforce through the SOAP API. I am a complete newb with PHP, SOAP and SalesForce. Great assignment, huh?
Got most things working by following example code, but I just cannot find a sample of how to send MySQL datetime values through the SF create() method for dateTime fields. I've tried various formats and type casts using PHP functions, but to no avail.
If someone could share a working code snippet of assigning a MySQL datetime to a stdclass field in PHP in the appropriate fomat to be accepeted by Salesforce's create() method, I would sure appreciate it.
Thanks
Finally got this working.
I tried Redsummit's approach, but the input format to the date() function wan't right. The dates were accepted by Salesforce, but came out as nothing (that date in 1969).
So I traced the format of everything from the database forward. To go from a MySQL date data type to a Salesforce date data type:
= date_format(date_create_from_format('Y-m-d', $row['colname']), 'Y-m-d');
And to go from a MySQL datetime data type to a Salesforce datetime data type:
= date_format(date_create_from_format('Y-m-d H:i:s', $row['colname']), 'c');
I set the default time zone at the beginning of the script, so adjustment got made auto-magically ... give or take a daylight savings time or two, anyway. more keywords Salesforce SOAP API PHP ISO 8601
All Answers
The function date('c',$datetime_value) will format the string correctly. If you are populating a date field, the format is 'Y-m-d' rather than 'c'. The PHP documentation will explain what these produce, and you can use print_r($resulting_value) to see it.
Remember that all times in Salesforce are stored in UTC, so you may need to convert if you have times from other zones. Take a look at gmtdate() in the PHP doc for more information.
Park
Finally got this working.
I tried Redsummit's approach, but the input format to the date() function wan't right. The dates were accepted by Salesforce, but came out as nothing (that date in 1969).
So I traced the format of everything from the database forward. To go from a MySQL date data type to a Salesforce date data type:
= date_format(date_create_from_format('Y-m-d', $row['colname']), 'Y-m-d');
And to go from a MySQL datetime data type to a Salesforce datetime data type:
= date_format(date_create_from_format('Y-m-d H:i:s', $row['colname']), 'c');
I set the default time zone at the beginning of the script, so adjustment got made auto-magically ... give or take a daylight savings time or two, anyway. more keywords Salesforce SOAP API PHP ISO 8601