Friday, May 25, 2012

Converting C# DateTime to Salesforce.com DateTime

One of the most common tasks I need to do when dealing with Salesforce.com Partner or Enterprise WSDL is that I need to convert Microsoft DotNet Framework date & time to format that it is understood by Salesforce.com; whether it be using it in a query or using it with Partner API to create a record that has a date & time field.  To make my own life easier, I've created a very simple one liner method to do this job for me:


   1:  public static string ConvertToForceDateTime(DateTime dateTime)
   2:  {
   3:      dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
   4:      return dateTime.ToString("yyyy-MM-ddTHH:mm:ssZ");
   5:  }

I find that sometime creating simple one liner methods can make life so much easier.

Happy Coding

4 comments: