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
fredkafredka 

string.valueOF(UNI.start_date__c.Month() How do I ensure 2 digits?

Is there a way to add the leading 0 for single digit months using

 

string.valueOF(UNI.start_date__c.Month()

 

Currently, this returns 1 for January.. I would like it to return 01

 

Any help is greatly appreciated!!!!

 

Fred

Best Answer chosen by Admin (Salesforce Developers) 
Richa KRicha K

Hi Fred,

I am not sure if this is what you are asking. But try,

string chck = '';
if(UNI.start_date__c.Month() <= 9)
{
chck = '0'+ string.valueOf(UNI.start_date__c.Month());
}
else
{
 chck = string.valueOf(UNI.start_date__c.Month());
}
system.debug('================Date==========   '+chck);

 

All Answers

Richa KRicha K

Hi Fred,

I am not sure if this is what you are asking. But try,

string chck = '';
if(UNI.start_date__c.Month() <= 9)
{
chck = '0'+ string.valueOf(UNI.start_date__c.Month());
}
else
{
 chck = string.valueOf(UNI.start_date__c.Month());
}
system.debug('================Date==========   '+chck);

 

This was selected as the best answer
fredkafredka

Thats exactly what I was looking for.. thanks Shailesh!!!!

 

FRed