+ Start a Discussion
sd2008sd2008 

Question: Initial term of field expression must be a concrete SObject:Datetime

I got the message for the following code:

 

 

public class FirstClass

{

    public Integer tm()

    {

      Datetime mytime = datetime.now();

      Integer h = mytime.hour;

        return h;

    }

}

 

 

 

I also tried the following, but still not right.

 

 

public class FirstClass

{

    public string tm()

    {

      Datetime mytime = datetime.now();

      string h = string.valueof(mytime.hour);

        return h;

    }

}

Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae

hour is a method call and needs to have the () after it.

 

 

public class FirstClass { public Integer tm() { Datetime mytime = datetime.now(); Integer h = mytime.hour(); return h; } }

 

 

All Answers

JimRaeJimRae

hour is a method call and needs to have the () after it.

 

 

public class FirstClass { public Integer tm() { Datetime mytime = datetime.now(); Integer h = mytime.hour(); return h; } }

 

 

This was selected as the best answer
sd2008sd2008
thank you