+ Start a Discussion
SalesRedSalesRed 

Display Day and Month values using 2 characters (if s single digit day or month)

Hello,

 

In my visualforce page I have the following line for displaying the day/month/year from a datetime field

 

{!DAY(DATEVALUE(quoteItem.Quoted_Date__c))}/{!MONTH(DATEVALUE(quoteItem.Quoted_Date__c))}/{!YEAR(DATEVALUE(quoteItem.Quoted_Date__c))}

 

if my day is the 3rd  (i.e. 3), 4th etc (any single character less than 10)  I wish to display 2 characters (i.e. a "0" before the day) on my page.   SImilarly for months.

 

Does anyone know of the best way to do this?

 

Thanks in advance!

Best Answer chosen by Admin (Salesforce Developers) 
Coco_SdyneyCoco_Sdyney

{!RIGHT(TEXT(DAY(DATEVALUE(quoteItem.Quoted_Date__c))+ 100), 2)}

All Answers

Coco_SdyneyCoco_Sdyney

convert a integer which less than 99  to two chars:

 

String s = string.valueof(integer+100).right(2);

SalesRedSalesRed

Hi Coco,

 

Thanks for your help.  Can this be done in visualforce and not in the apex class?

 

Thanks.

Coco_SdyneyCoco_Sdyney

RIGHT(TEXT(VALUE(your integer day) + 100), 2)

SalesRedSalesRed

Hi Coco,

 

Thanks for your help.

 

On trying the following

 

{!RIGHT(TEXT(VALUE(DAY(DATEVALUE(quoteItem.Quoted_Date__c)))+ 100), 2)}

 

I get an error on saving it in eclipse as follows

 

"Save error: Incorrect parameter type for function 'VALUE()'. Expected Text, received Number"

 

Do you know what I may be putting wrong here?

 

Thanks.

Coco_SdyneyCoco_Sdyney

{!RIGHT(TEXT(DAY(DATEVALUE(quoteItem.Quoted_Date__c))+ 100), 2)}

This was selected as the best answer
SalesRedSalesRed

Great,  thanks for your help. It works perfectly!