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
Satya413Satya413 

Strip Time from Date Field

Hello Everyone, 

I would like to strip the time of the dynamically referenced date field as shown below. Any help is appreciated. 

Controller: 

public class examschedule1_con {

   public exam_schedule__c es {get; set;}
   public list<exam_schedule__c> ess {get; set;}
   public map<string,list<date>> maplist{get; set;}
   
   public examschedule1_con()
   {
     es = new exam_schedule__c();
   }
   
   public void getdata()
   {
     maplist = new map<string,list<date>>();
     
     ess = [select name, startdate__c, enddate__c, starttime__c, endtime__c, year__c, examtype__c, 
           subject1__c, subject2__c, subject3__c, subject4__c, subject5__c, subject6__c, subject7__c 
           from exam_schedule__c where year__c = :es.year__c ];
           
     for(exam_schedule__c e : ess)
     {
        if(!maplist.containskey(e.examtype__c))
        maplist.put(e.examtype__c,new list<date>());
        maplist.get(e.examtype__c).add(e.subject1__c);
        maplist.get(e.examtype__c).add(e.subject2__c);
        maplist.get(e.examtype__c).add(e.subject3__c);
        maplist.get(e.examtype__c).add(e.subject4__c);
        maplist.get(e.examtype__c).add(e.subject5__c);
        maplist.get(e.examtype__c).add(e.subject6__c);
        maplist.get(e.examtype__c).add(e.subject7__c);
     }
   } 
}

VF Page: 

<apex:page controller="examschedule1_con" showHeader="false">
 <apex:form >
  <apex:pageBlock >
   <apex:pageblockSection title="Enter Exam Details">
    <apex:inputfield value="{!es.Year__c}"/>
    <apex:commandButton value="Submit" action="{!getdata}"/>
   </apex:pageblocksection>
  </apex:pageblock>  
  <table border="1" width="600" align="center">
  <th>Exam Type</th>
  <th>Subject1</th>
  <th>Subject2</th>
  <th>Subject3</th>
  <th>Subject4</th>
  <th>Subject5</th>
  <th>Subject6</th>
  <th>Subject7</th>
  <apex:repeat value="{!maplist}" var="key">
  <tr>
  <td>{!key}</td>
  <apex:repeat value="{!maplist[key]}" var="value">
  <td>{!value}</td>
  </apex:repeat>
  </tr>
  </apex:repeat>
  </table>
 </apex:form>
</apex:page>

My Output: 

User-added image

Thank you,
Satya
Best Answer chosen by Satya413
Keyur  ModiKeyur Modi
Hi,
If you want to display the time from dateTime /date field then refer below code .. which will give you the clear idea.
 
// From date Time field Time 

<apex:outputText value="The formatted time right now is: 
         {0,date,HH:mm:ss}">
       <apex:param value="{!NOW()}" />
   </apex:outputText>


// in your code you can use it like this

  <apex:repeat value="{!maplist[key]}" var="value">
  <td>
<apex:outputText value="The formatted time right now is: {0,date,HH:mm:ss}"> <apex:param value="{!value}" /> </apex:outputText>
</td>
  </apex:repeat>

And one more thing as you are displaying date field so that field always have time = 00 .. so if you want to diisplay the time then you can use dataTime field.

please let me know if this will help

Thanks,
Keyur Modi

 

All Answers

Keyur  ModiKeyur Modi
Hi,
If you want to display the time from dateTime /date field then refer below code .. which will give you the clear idea.
 
// From date Time field Time 

<apex:outputText value="The formatted time right now is: 
         {0,date,HH:mm:ss}">
       <apex:param value="{!NOW()}" />
   </apex:outputText>


// in your code you can use it like this

  <apex:repeat value="{!maplist[key]}" var="value">
  <td>
<apex:outputText value="The formatted time right now is: {0,date,HH:mm:ss}"> <apex:param value="{!value}" /> </apex:outputText>
</td>
  </apex:repeat>

And one more thing as you are displaying date field so that field always have time = 00 .. so if you want to diisplay the time then you can use dataTime field.

please let me know if this will help

Thanks,
Keyur Modi

 
This was selected as the best answer
Satya413Satya413
Hi Keyur,

Thanks for your reply. Actually, I put the question somewhat unclear. I actually want to take the time away and display only the date from the date field. 

Thank you,
Satya
Keyur  ModiKeyur Modi
Hi,
you can do the same with code which i shared .. just chane it as mention below
 
<apex:outputText value="The formatted time right now is: 
         {0,date,yyyy/MM/dd}">
       <apex:param value="{!NOW()}" />
   </apex:outputText>


// you can change the format of the date as per your requirement 
likein place of yyyy/mm/dd   you can give ... yy/mm/dd   , mm/dd/yy, dd/mm/yy 

in your case you can use it like


<apex:repeat value="{!maplist[key]}" var="value">  
 <td> 

<apex:outputText value="The formatted time right now is: {0,date,yyyy/MM/dd}"> 
<apex:param value="{!value}" /> 
</apex:outputText>

 </td> 
 </apex:repeat>

please let me know if this will help,

Thanks,
Keyur Modi
 
Satya413Satya413
Cool. Just found that out. Thanks

Thank You,
Satya