Wednesday, January 27, 2010

IF THEN STATEMENT IN VF plus Format of Dates in Force.com

Hi:
   Scenario:
        I had to do an IF THEN STATEMENT off from a date to place a date range into a VF Page.
Issue I had was the date Formating, because when you place a formula to do a Date it comes out as YYYY-MM-DD
I needed DD-MM-YYYY
So this is what I did:
I created a table that has columns and the resulted row:
So two tags here being used are :
apex:column
apex:outputLabel

First the Column:
            apex:column headerValue="Date Range          
           apex:outputLabel value="{!IF(DAY(TODAY())>15,
            RIGHT(TEXT(TODAY()), 2) & "/" &
            MID(TEXT(TODAY()), 6, 2) & "/" &
            LEFT(TEXT(TODAY()), 4)& " to " &
            RIGHT(TEXT(item.Last_Day_of_Month__c), 2) & "/" &
            MID(TEXT(item.Last_Day_of_Month__c), 6, 2) & "/" &
            LEFT(TEXT(item.Last_Day_of_Month__c), 4)
            ,
            IF(DAY(TODAY())<15,
            MID(TEXT(TODAY()), 6, 2) & "/" &
            RIGHT(TEXT(TODAY()), 2) & "/" &
            LEFT(TEXT(TODAY()), 4) & " to " &
            RIGHT(TEXT(item.Last_Day_of_Next_Month__c), 2) & "/" &
            MID(TEXT(item.Last_Day_of_Next_Month__c), 6, 2) & "/" &
            LEFT(TEXT(item.Last_Day_of_Next_Month__c), 4),
            'FALSE'))
            }"/>
           
Now the thing is Last_Day_of_month__c and Last_Day_of_Next_Month are formulas Date Fields I created...
You can find the formulas on
http://mysalesforcecode.blogspot.com/2010/01/determine-end-of-month-date-or-days.html
Thanks
Check out my Other Salesforce.com Blogs
Salesforce Made Easy

Salesforce Data Migration Made Easy
eTechCareers.com Coming Soon