+ Start a Discussion
kiran punurukiran punuru 

Remove time format from date field

Hi All,
I have one field startdate__c which is of type date field when iam using this field in the soql query and displaying that field it is giving the format like : 2016-05-03 00:00:00 .How can i remove 00:00:00 and display only date ? Can someone advise .

Thanks,
Kiran
Veenesh VikramVeenesh Vikram

Hi,

In Apex, you can achieve the same by converting datetime values to date.
DateTime dT = System.now();
Date myDate = date.newinstance(dT.year(), dT.month(), dT.day());

OR you can use Function DATEVALUE, Like:
DATEVALUE(startdate__c);

Hope this helps. Kindly mark as Solved if this resolves your issue.

Regards
Veenesh

 

Srinivas SSrinivas S
If you use outputField, It will be formatted automatically as per the user time zone else please follow the below link on formatting the date in visualforce page -
http://salesforce.stackexchange.com/questions/22321/visualforce-date-formatting

------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
mritzimritzi
I believe you are talking about VisualForce Page.

Use following code, to get only date
<apex:outputText value="{0, DATE, MMM dd',' yyyy}">
    <apex:param value="{!objectVariableName.startdate__c}"/>
</apex:outputText>
variation:
<apex:outputText value="{0, DATE, dd'/'MM'/' yyyy}">
    <apex:param value="{!objectVariableName.startdate__c}"/>
</apex:outputText>

replace objectVariableName with actual sObject name.

If this helps you out, please mark this as Best Answer.
cloudSavvyProgcloudSavvyProg
Hi Kiran,

I have used apex:outputText for formatting on VF pages. It works well.

<apex:page>
2   <apex:outputText value="The unformatted time right now is: {!NOW()}" />
3   <br/>
4   <apex:outputText value="The formatted time right now is:
5         {0,date,yyyy.MM.dd G 'at' HH:mm:ss z}">
6       <apex:param value="{!NOW()}" />
7   </apex:outputText>
8</apex:page>

Doc to give you more info:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_outputText.htm   

Hope this helps.

Regards,
CloudSavvyProg
kiran punurukiran punuru
Thankyou one and all i have solved that problem using format() and  it is working: 
    startdate__c.format()
Meer ZamanMeer Zaman
Hi kiran punuru,

If we convert Date field to string it will remove time string from date and we can use same string in query. This looks simple to me.

Thanks,
Zaman