1

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

2014-09-16T11:55:00.000Z

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

1

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.

2
  • 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
1

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 :).

-1

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

    System.debug(formatDate('2014-09-16T11:55:00.000Z'));
    public static Date formatDate(Object dateObject)
    {
        String dateString = String.valueOf(dateObject);
        List<String> dateStringList = dateString.split('T');
        if(dateStringList.size()==2)
        {
            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.