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
Gavin BrittoGavin Britto 

Format Date in Visual Force page

I need Help converting 2016-01-08T19:00:00 to 01/08/2016

I want to truncate the time (19:00:00 )

This is what I wrote:
 
<apex:column headerValue="Event Date">
                           <apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
                            <apex:param value="{!listMysticsmailMap[m].eventDateTime}" />
                        </apex:outputText>
                     </apex:column>



However, I get the following error: Content cannot be displayed: The value attribute on <apex:outputText> is not in a valid format. It must be a positive number, and of type Number, Date, Time, or Choice.

I then tried
 
<apex:outputText value="{0,date,MM/dd/yyyy}">



That didn't work either
 
Best Answer chosen by Gavin Britto
Naval Sharma4Naval Sharma4
Hi Gavin,

It seems that issue is not with apex:outputText. I think your map is creating problem here. I am wondering if this works with map collection in visualforce pages. Can you try this with creating a simple datetime variable in wrapper or some other way around this.

All Answers

Naval Sharma4Naval Sharma4
Hi Gavin,

Just a little modification in your code.
<apex:column headerValue="Event Date">
                           <apex:outputText value="{0,date,MM/dd/yyyy}">
                            <apex:param value="{!listMysticsmailMap[m].eventDateTime}" />
                        </apex:outputText>
                     </apex:column>

Let me know if it works for you.

Regards,
Naval
Gavin BrittoGavin Britto
Hi Naval,

Thank you for looking into my formatting challenge. I did try that and it still gave me the error "Content cannot be displayed: The value attribute on <apex:outputText> is not in a valid format. It must be a positive number, and of type Number, Date, Time, or Choice."

I think the conversion is failing because  2016-01-08T19:00:00 <-- this time element

I need to convert to MM/dd/yyyy  or truncate the T19:00:00 

Any advice on this will be greatly appreciated
Naval Sharma4Naval Sharma4
Hi Gavin,

It seems that issue is not with apex:outputText. I think your map is creating problem here. I am wondering if this works with map collection in visualforce pages. Can you try this with creating a simple datetime variable in wrapper or some other way around this.
This was selected as the best answer
ALI WAHEEDALI WAHEED

I see that you resolved this issue. But for futur, you may also use the Help and Training tab in the upper right corner. Give this link a shot as well. All thes best

https://developer.salesforce.com/forums?id=906F000000097k0IAA

Gavin BrittoGavin Britto
You are right Naval. I have declared eventDateTime as string 

public String eventDateTime{get;set;}

So its trying to convert a string into date. So if I declare the eventDateTime Map to return a date value, would it work?
Naval Sharma4Naval Sharma4
Hi Gavin,

You can give it a shot but sometimes this formatting doesn't work with Maps.

Thanks,
Naval