While trying to retrieve the headers from an integration response, I am getting a Datetime value in String format in the Header.

Format - Mon, 01 Jul 2019 10:20:06 GMT I need to compare this with the lastmodifieddate of Account.

Code :

        String strDate = headers.get('Date');
        DateTime lastmodified = DateTime.valueOfGmt(strDate);
        String utcDt = lastmodified.format('yyyy-mm-dd', 'UTC');
        system.debug('!===lastmodified : '+lastmodified);
  • 1
    what you have tried so far? Jul 1, 2019 at 10:40
  • I have used the datetime.format,datetimeGmtformat,datetime,valueof,DateTime.valueOfGmt.
    – Aditya
    Jul 1, 2019 at 10:49

1 Answer 1


It can be done by formatting lastmodifieddate to String.

Here is the example:

Datetime x = Datetime.now();
String s = x.formatGMT('EEE, dd MMM yyyy HH:mm:ss') + ' GMT';
system.debug(s); // Mon, 01 Jul 2019 10:39:14 GMT

After that you can compare the header value.

Links to documentation:



  • I don't think this is going to work. It is the extension of this . salesforce.stackexchange.com/questions/267745/… Added a comment over in that URL as well.
    – Aditya
    Jul 1, 2019 at 12:29
  • Datetime account_lastModifiedDate = someAccount.LastModifiedDate; system.assertEquals(header_lastModifiedDate, account_lastModifiedDate.formatGMT('EEE, dd MMM yyyy HH:mm:ss') + ' GMT'); @Aditya That's not true, in the case like this it's going to work. What you are trying to do is convert string to datetime. In cintrast, I am converting datetime (lastmodifieddate of account) to string and comparing it to the header string. Jul 1, 2019 at 13:02
  • It seems to work . Thanks
    – Aditya
    Jul 1, 2019 at 14:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .