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
Dchris222Dchris222 

Query Result Dateformat

How do you format the output of a date field in Visualforce? I want to evalute the date in a series of if else statements, but I am  recieving a long number such as 1299542400000 when the querry runs. How can I format the output to be usefull?? Thanks in advance.

 

 

List<Opportunity> Opptys2 = [SELECT LastActivityDate, Activity_Status__c FROM Opportunity ORDER BY LastActivityDate DESC];	

List<OpportunityFeed> Opptys = [SELECT id, (SELECT CreatedDate FROM FeedComments ORDER BY CreatedDate DESC) FROM OpportunityFeed];

 

 

 

Chris

Best Answer chosen by Admin (Salesforce Developers) 
MiddhaMiddha

Yes, that 0 was just to give you an example and fetch the first element of the list.

 

to iterate the complete record set, you can use a for loop:

 

 

List<Opportunity> Opptys2 = [SELECT LastActivityDate, Activity_Status__c FROM Opportunity ORDER BY LastActivityDate DESC];	

for(Opportunity o: Opptys2)
{
    Datetime st = o.LastActivityDate;
}

 

 

All Answers

MiddhaMiddha

I tried this query and it gives : "2009-09-10 16:44:11".

 

Try assigning the result in a Datetime type variable.

Dchris222Dchris222

I tried that and It says Illegal assignment from Schema.SObjectField to Datetime.

 

 

datetime Da = Opportunity.LastActivityDate;

 

 

MiddhaMiddha

This is not correct. It should be:

 

 

List<Opportunity> Opptys2 = [SELECT LastActivityDate, Activity_Status__c FROM Opportunity ORDER BY LastActivityDate DESC];	

Datetime st = Opptys2[0].LastActivityDate;

 

 

Dchris222Dchris222

For learning purposes, is the 0 the record number in the list? If i am using a loop, what would be the best way to go to the next record each time?

MiddhaMiddha

Yes, that 0 was just to give you an example and fetch the first element of the list.

 

to iterate the complete record set, you can use a for loop:

 

 

List<Opportunity> Opptys2 = [SELECT LastActivityDate, Activity_Status__c FROM Opportunity ORDER BY LastActivityDate DESC];	

for(Opportunity o: Opptys2)
{
    Datetime st = o.LastActivityDate;
}

 

 

This was selected as the best answer
Dchris222Dchris222

That makes sense, thank you so much!