You need to sign in to do that
Don't have an account?
Naga Balji B
how to separate date and time fields of createddate in page block table
VF page:
<apex:page controller="Time_date" sidebar="false">
<apex:form >
<apex:pageBlock title="Displaying all records of s object">
<apex:pageBlockSection columns="1">
<apex:pageBlockTable var="b" value="{!bk}" cellpadding="4" cellspacing="4">
<apex:column headervalue="Name" value="{!b.name}"/>
<apex:column headervalue="EDITION" value="{!b.Edition__c}"/>
<apex:column headervalue="Price" value="{!b.price__c}"/>
<apex:column headervalue="Created Date">
Date:<apex:outputText value="{!dt}"/>
Time:<apex:outputText value="{!tm}"/>
</apex:column>
<apex:column headervalue="modified Date" value="{!b.LastModifiedDate}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class:
public with sharing class Time_date {
public time tm { get; set; }
public date dt { get; set; }
public List<book__c> bk { get; set; }
public Time_date(){
bk=[select id,name,edition__c,price__c,Createddate,lastmodifieddate from book__c];
//dt=DATEVALUE(CreatedDate);+
//tm=MID(TEXT(CreatedDate - 0.1667), 12, 5);
datetime Createddate;
//dt=Createddate.date(); //display Error
//tm=Createddate.Time();
}
}
Output:
<apex:page controller="Time_date" sidebar="false">
<apex:form >
<apex:pageBlock title="Displaying all records of s object">
<apex:pageBlockSection columns="1">
<apex:pageBlockTable var="b" value="{!bk}" cellpadding="4" cellspacing="4">
<apex:column headervalue="Name" value="{!b.name}"/>
<apex:column headervalue="EDITION" value="{!b.Edition__c}"/>
<apex:column headervalue="Price" value="{!b.price__c}"/>
<apex:column headervalue="Created Date">
Date:<apex:outputText value="{!dt}"/>
Time:<apex:outputText value="{!tm}"/>
</apex:column>
<apex:column headervalue="modified Date" value="{!b.LastModifiedDate}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class:
public with sharing class Time_date {
public time tm { get; set; }
public date dt { get; set; }
public List<book__c> bk { get; set; }
public Time_date(){
bk=[select id,name,edition__c,price__c,Createddate,lastmodifieddate from book__c];
//dt=DATEVALUE(CreatedDate);+
//tm=MID(TEXT(CreatedDate - 0.1667), 12, 5);
datetime Createddate;
//dt=Createddate.date(); //display Error
//tm=Createddate.Time();
}
}
Output:
I have updated you class and VF page. This should work for you.
Class
vf Page
Hope your problem is resolved.
All Answers
I have updated you class and VF page. This should work for you.
Class
vf Page
Hope your problem is resolved.
if i am use above code...getting Below error .
Error: Time_date Compile Error: The property Date dt is referenced by Visualforce Page (Task40_Time_date111) in salesforce.com. Remove the usage and try again. at line 5 column 17
First try to comment your entire vf page and then save your class. Once its saved then uncomment the vf ppage and save it. should work
Thanks for your fast response...ur coding works good but in time zone output shows excess...unwanted "000Z".how to remove it. is there any simple way to time shows in 12 hours mode(am,pm). and alsodate dispalay like jan,feb etc(like ..12th jan 2016)
Hi Naga,
here is the link to the time class and its method. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_time.htm
you can do some thing like this :
Time tt = aa.lastmodifieddate.time();
String timeFormat = tt.hour()+':'+tt.time().minute()+':'+tt.time().second();
System.debug('timeFormat: '+timeFormat);
OR you can simply remove the last "000Z" by
String time = ''+aa.lastmodifieddate.time();
String formattedTm = time.mid(0,8);
Result will be : 00:02:02
In either way you have to then update the datatype of
public Time LastTm {get;set;}
to
public String LastTm {get;set;}