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 Name = 'TestName' AND CreatedDate > 2005-10-08T01:02:03Z
Select CreatedDate, Id, LastModifiedDate from Opportunity where Name = 'TestName' AND 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 CreatedDate, Id, LastModifiedDate from Opportunity where CreatedDate >: myDate AND CreatedDate <: myDate2 AND Name = 'TestName' order by LastModifiedDate];
// Controller Class
public class Controller {
public Date ed { get; set; }
public Date sd { get; set; }
public String name { get; set; }
public List<Candidate__c> C {get;set;}
public Controller(){
C= new List<Candidate__c>();
}
public PageReference fetchValues() {
C=[select Name, First_Name__c, Last_Name__c from Candidate__c where (First_Name__c like:name) AND (First_Name__c like:name+'%') AND (First_Name__c like:'%'+name+'%')AND (Start_Date__c>=:sd) AND (End_Date__c<=:ed)];
return null;
}
}
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 that searches for records based on the name and date ranges in a Visualforce page.
Hope this helps you!
Best Regards,
Deepthi
Please check the below sample code.
VisualForce Page:
Controller:
Screenshot:
Hope this helps you!
Best Regards,
Jyothsna