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
bharath kumar 52bharath kumar 52 

Display only "date" from "datetime" field on vf page

Hi All,

I am working on a requirement where the metadata type of the field is datetime and is used in several places. However, in one of the vf pages i need to show only the "date" which needs to be extracted from datetime.

Here's what i tried :
1.) Assign the value from datetime field to a string variable to get the substring.(NOT possible to assign datetime to string)
2.)Assign the value from datetime to date. In this case i get a totally different date value i.e with a difference of almost a month.
Below is the snippet for the same.

datetime finishDatetime;// datetime
date finishDate; // date only

finishDatetime= sr.CKSW_BASE__Finish__c;;   //This gives me the value of Feb 28th when converted to date along with a string of 0's and GMT where as the original value in the backend is around March 15th.

Any suggestions would be greatly helpful.

Thanks and Regards,
Bharath Kumar M
NagendraNagendra (Salesforce Developers) 
Hi Bharath,

Please try the below code and let us know if it works.
<apex:outputText value="{0,date,yyyy.MM.dd}">
   <apex:param value="{!MyVar.Holiday_Date__c}"/>
Where instead of MyVar.Holiday_Date__C use your DateTime variable name.

Mark this as solved fi it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering similar issue.

Best Regards,
bharath kumar 52bharath kumar 52
But, how do you make it work with apex:column ?
Below is the code  in which i am supposed to make the change.
<apex:column value="{!srvc.CKSW_BASE__Finish__c }" headerValue="Finish time"/>

Harshit Porwal 7Harshit Porwal 7

@Nagendra It's working.
 Thanks :-)