In a SOQL query you can specify either a particular date or a date literal. A date literal is a fixed expression that represents a relative range of time, such as last month, this week, or next year.
dateTime field values are stored as Coordinated Universal Time (UTC). When a dateTime value is returned in Salesforce, it’s adjusted for the time zone specified in your org preferences. SOQL queries, however, return dateTime field values as UTC values. If you want to process these values in different time zones, your application might need to handle the conversion.
Some of the sample SOQL:
SELECT Id
FROM Account
WHERE CreatedDate > 2005-10-08T01:02:03Z
Select CreatedDate, Id, LastModifiedDate
from Opportunity
where CreatedDate > 2011-01-01T00:00:00Z and CreatedDate < 2011-12-31T00:00:00Z
Date myDate = date.newinstance(2011, 1, 1);
Date myDate2 = date.newinstance(2011, 12, 31);
List<Opportunity> oppLst = [Select o.CreatedDate, o.Id, o.LastModifiedDate from Opportunity o where o.CreatedDate >: myDate and o.CreatedDate <: myDate2 order by o.LastModifiedDate] ;
public with sharing class DateRangeCont {
public list<customer__c> customer1 { get; set; }
public datetime startdate1;
public datetime enddate1;
public customer__c a { get; set; }
public DateRangeCont(){
customer1=new list< customer__c>();
a=new customer__c();
}
public PageReference go() {
startdate1=a.From_Date__c;
enddate1=a.To_Date__c;
customer1=[select name,Billing_City__c ,Billing_Postal_Code__c,Createddate from customer__c where Createddate>=:startdate1 AND Createddate<=:enddate1];
return null;
}
}
Date Formats and Date Literals:
In a SOQL query you can specify either a particular date or a date literal. A date literal is a fixed expression that represents a relative range of time, such as last month, this week, or next year.
dateTime field values are stored as Coordinated Universal Time (UTC). When a dateTime value is returned in Salesforce, it’s adjusted for the time zone specified in your org preferences. SOQL queries, however, return dateTime field values as UTC values. If you want to process these values in different time zones, your application might need to handle the conversion.
Some of the sample SOQL:
Also Please go through the below links:
https://nextgensalesforce.wordpress.com/2015/11/30/dynamic-soql-query-results-in-local-time/
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm
Please do let me know if it helps you.
Regards,
Mahesh
Please check the below sample code.
VisualForce Page:
Controller:
Screenshot:
Hope this helps you!
Best Regards,
Jyothsna