I have a date field in my object. After I fire a select query , the returned format of the date is :


I have a requirement where I need to convert the above date into System.today() format. Any inputs in this regard is helpful.


The field that you query is a date time field by the looks of it. In order to get the date component of that you need to use the DateTime.date() method.

  • Thanks Bachovski,But when I use DateTime.date() it gives the following error: "Variable does not exist: DateTime". – Pravalika Maram Oct 1 '14 at 5:50
  • 1
    @PravalikaMaram use with DateTime instance not with "DateTime" itself. – Ashwani Oct 1 '14 at 6:03

You can use following method to get DateTime in System.today() formate

public Date getdateOnly(DateTime fieldValue){
  return fieldValue.date();

Please mark this as an answer if this helps you :).


You will need to format the string/object into valid string first then convert to date:

    public static Date formatDate(Object dateObject)
        String dateString = String.valueOf(dateObject);
        List<String> dateStringList = dateString.split('T');
            return Date.valueOf(dateStringList[0]);
        return null;

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.