+ Start a Discussion
Peter KayePeter Kaye 

Convert MySQL datetime to format for use in SOQL in php

I want to convert a date time like 2016-09-01 17:49:46 to 2016-09-01T17:49:46Z.

The best I can manage so far is:

$the_date = "2016-09-01 17:49:46"

date("Y-d-mTG:i:sz",$the_date)  which gives  2016-01-09UTC17:49:46244

What is the correct way to get the date time format that will work in a SOQL query ? Thanks.

 
Peter KayePeter Kaye
This works but it's not very elegant.
$maxresult = "2106-09-01 11:11:34";
$soqldate = substr($maxresult,0,10)."T".substr($maxresult,11,8)."Z";
Is there a better way ?
 
Don KellyDon Kelly
Peter, I realize this is a very old thread, but the best way I've found to do this is to Modify your MySql query to use the Date_Format Funtion with the following format string '%Y-%m-%dT%TZ' which outputs the date in the correct format for SOQL 

Hope this helps!!