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
MicheleMcgeoyMicheleMcgeoy 

Dispalying date only

I am trying to concatentate a text field with a date without including the time and am getting an error: Method does not exist or incorrect signature: [Date].format(String)

 

     Date NewDate = Camp.Startdate;

// Line below gives CampName2013-12-02 00:00:00
        NewCamp1.Name = camp.name + NewDate;


// Line below gives error: Method does not exist or incorrect signature: [Date].format(String)
       NewCamp1.Name = camp.name + NewDate.format('MM/dd/yyyy');

What am I doing wrong?

 

Thanks, Michele

Best Answer chosen by Admin (Salesforce Developers) 
Subhash GarhwalSubhash Garhwal

Hi,

 

If you only want to remove time from date than you can simply do this 

 

//Line below give CampName2013-12-07 

NewCamp1.Name = camp.name + String.valueOf(NewDate);

 

Or if you want format method than use dateTime

 

// Line below give CampName07/12/2013
NewCamp1.Name = camp.name + NewDate.format();

 

Or for DateTime you can format

 

DateTime NewDate = System.now();

 

// Line below give CampName12/07/2013
NewCamp1.Name = camp.name + NewDate.format('MM/dd/yyyy');

 

Thanks

 

Hit the Kudos button (star)  and Mark as solution if it post helps you