function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
anurajanuraj 

Date

Hi 

Tell me how to find out the month from date.

I have done like this 

  public datetime takemonth;
public PageReference month() 
    {
       
     //  date duedate =  date.today();
       date dueDue = Date.newInstance(takemonth.year(),takemonth.month());
      // integer dueNow = duedate.month(dueDate);
      system.debug('++++++++++++++++++++++++'+ dueDue );
       return dueDue ;
    }

 And i am getting the error

Error: ctrl_sch Compile Error: Method does not exist or incorrect signature: Date.newInstance(Integer, Integer) at line 30 column 22

 

thanks 

Anuraj

Best Answer chosen by Admin (Salesforce Developers) 
r1985r1985

Hi,

 

Use the below code.

 

date duedate =  date.today();
Integer month=duedate.month();
System.debug('Month is -->'+month);

 

 

Thanks,

MVP

 

All Answers

r1985r1985

Hi,

 

Use the below code.

 

date duedate =  date.today();
Integer month=duedate.month();
System.debug('Month is -->'+month);

 

 

Thanks,

MVP

 

This was selected as the best answer
Sam27Sam27

you are getting this error because your syntax for creating date is not correct.

Date Duedue = Date.newInstance(takemonth.year(),takemonth.month(),takemonth.day());

integer month = Duedue.month();

 

However it's bit weird coz takemonth.month() will give you month as an integer if takemonth is a date object, can you tell what is takemonth? and what value it holds?