I am making a SOAP callout from Apex for that I have to pass one date value as parameter in that callout. When I try pass a value as date.valueof(system.today()) time is also getting appended but as per the SOAP request that field is in xsd:date its accept date only in this format yyyy-MM-dd.

I am confused how to achieve this. Looking your help if anyone have done this before.

serviceCheck.ShipDate = date.valueOf(system.today());

but the date coming as in this format 2020-05-11 00:00:00. I have to remove the time value.


You can parse the date using string methods

serviceCheck.ShipDate = String.valueOf(System.today()) //Result: 2020-05-11

Please note that the System.today will execute based on your timezone so it is best to send the timezone information as well or UTC offset or send the GMT date using

  • I generated the apex class from wsdl in that it created that field as date. Can I change the datatype as String and shall i try? – Mangoski May 11 '20 at 18:24
  • 1
    Yes, you can do that unless it has a lot of dependencies. It is useful to have a Date type if when you have an inbound soap service as Salesforce create a dat object from it. – manjit5190 May 11 '20 at 18:33
  • It helps a lot. Thank you – Mangoski May 11 '20 at 18:57

Firstly, you need to convert date into DateTime.

Then, if you want the date in the local time zone of the user, use below code

DateTime myDateTime = DateTime.newInstance(system.today().year(),system.today().month(), system.today().day(), 0 , 0,0);
String strDate = myDateTime.format('yyyy-MM-dd');

If you want GMT

String strDate = myDateTime.formatGmt(dateFormatString);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.