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
Aidan PeoplesAidan Peoples 

How to get two digit day from a date formula e.g. 1st should be 01 2nd should be 02

Hi,

I have created a formula in a work flow to concatenate several fields to for a new field in opportunities, this works however for the date, I would like the day to show as two digits for day 1-9 in the month but I cannot seem to figure out how to update my formula (below) to manage this. The result I am looking to achieve is where a call date is 09/09/2017 should be returned as 09SEP17.

Thanks in advance
Aidan

Product2.ProductCode + '-' + Opportunity.Port__r.Port_Code__c + '-' + Opportunity.Ship__r.Code__c + '-' + 
TEXT(DAY(Opportunity.Call_Date__c)) + CASE(MONTH(Opportunity.Call_Date__c), 
1, "JAN", 
2, "FEB", 
3, "MAR", 
4, "APR", 
5, "MAY", 
6, "JUN", 
7, "JUL", 
8, "AUG", 
9, "SEP", 
10, "OCT", 
11, "NOV", 
12, "DEC", 
"None") + RIGHT(TEXT(YEAR(Opportunity.Call_Date__c)),2)
Aidan PeoplesAidan Peoples
just in case somebody else get stuck on this, here was the answer, LPAD(TEXT(DAY(Opportunity.Call_Date__c)),2,"0")
Cheri L.Cheri L.
Thank you! So simple, and too much Stack Exchange when I Googled! ;-)
Eden WheelerEden Wheeler
To get a two-digit day from a date formula, you can use the TEXT function in combination with the RIGHT function. Here's an updated version of your formula that includes the modification to achieve the desired result:
Product2.ProductCode + '-' + Opportunity.Port__r.Port_Code__c + '-' + Opportunity.Ship__r.Code__c + '-' +
RIGHT("0" + TEXT(DAY(Opportunity.Call_Date__c)), 2) + CASE(MONTH(Opportunity.Call_Date__c),
1, "JAN",
2, "FEB",
3, "MAR",
4, "APR",
5, "MAY",
6, "JUN",
7, "JUL",
8, "AUG",
9, "SEP",
10, "OCT",
11, "NOV",
12, "DEC",
"None") + RIGHT(TEXT(YEAR(Opportunity.Call_Date__c)), 2)

In the updated formula, the RIGHT("0" + TEXT(DAY(Opportunity.Call_Date__c)), 2) expression is responsible for ensuring the day is represented with two digits. It adds a leading zero (using the concatenation operator "+") to the day value and then extracts the rightmost two characters, effectively resulting in a two-digit day.azure developer course (https://www.igmguru.com/cloud-computing/microsoft-azure-developer-az-203-certification-training/)

With this modification, the formula should return the desired result, such as "09SEP17" for a call date of 09/09/2017.
Priddy brodericksonPriddy broderickson
To achieve the two-digit day format you're looking for, you can use the easy doors (https://karlogaragedoorsandgates.com/simple-and-easy-ways-to-keep-thieves-out-of-your-garage/) website DAY() function along with TEXT() function for formatting. Here's an example of how you can update your formula:
javascriptCopy code
TEXT(DAY(Date_Field), "00") & TEXT(Date_Field, "MMMYY")
This should help you display the day in a two-digit format (e.g., 09SEP17) regardless of whether it's a single-digit or double-digit day.