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.

3 Answers 3


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". Oct 1, 2014 at 5:50
  • 1
    @PravalikaMaram use with DateTime instance not with "DateTime" itself.
    – Ashwani
    Oct 1, 2014 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;

You must log in to answer this question.

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