Formats for dealing with dates and datetimes in Salesforce

The correct way to format dates (not datetimes!) for bulk importing CSVs into Salesforce looks like year-month-day, so today would look like 2019-06-17.  These default to the timezone set for the user importing them, so there’s no need to convert to UTC.  Set this in Excel by

  • Select the column/s containing dates
  • Right click on them and select “Format Cells” from the menu
  • Select the format “2012-03-14"
  • Save as CSV (not the UTF-8 type of CSV)


For programmatic imports, the correct .NET Framework DateTime format string to use for a Salesforce Date/time is:
yyyy-MM-ddTHH:mm:ss.fffZ
You can get the same thing in SQL using CONVERT(VARCHAR, datefield, 127) + ‘Z’. This also has the added advantage that Excel doesn’t interpret it as a date, so you don’t have to do the steps above.

Regardless of where you’re getting the datetime value from, make sure it’s in UTC! If the time represents the current moment, use DateTime.UtcNow

You might be tempted to use “O” (round-trip pattern) since it looks sort of similar, but don’t.  It won’t cause an error, but the time will be parsed incorrectly.

For using timezones instead of UTC (also works for querying Salesforce with SOQL), use a format like: 2019-08-01T00:00:00.000+0010