+ Start a Discussion
Balaji B 10Balaji B 10 

search a record by Date

Mahesh DMahesh D
Hi Balaji,

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:
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] ;

Also Please go through the below links:



Please do let me know if it helps you.


JyothsnaJyothsna (Salesforce Developers) 
Hi Balaji,
Please check the below sample code.

VisualForce Page:
<apex:page controller="DateRangeCont">
 <apex:form id="dt1">
 <apex:pageBlock >
 <apex:pageBlockSection >
 <apex:pageBlockSectionItem >
 <apex:outputLabel >Start Date</apex:outputLabel>
 <apex:inputfield value="{!a.From_Date__c}"/>
 <apex:pageBlockSectionItem >
 <apex:outputLabel >End Date</apex:outputLabel>
 <apex:inputField value="{!a.To_Date__c}"/>
<apex:commandButton value="Go" action="{!go}" reRender="dt"/>
 <apex:pageBlockTable value="{!customer1}" var="ct" id="dt">
<apex:column headerValue="Customer Name">
<apex:inputField value="{!ct.Name}"/>
<apex:column headerValue="billing city">
  <apex:inputField value="{!ct.Billing_City__c}"/>
  <apex:column value="{!ct.createddate}"/> 
  <apex:column headerValue="billing postal code">
  <apex:inputField value="{!ct.Billing_Postal_Code__c}"/>

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() {
    customer1=[select name,Billing_City__c ,Billing_Postal_Code__c,Createddate from customer__c where Createddate>=:startdate1 AND Createddate<=:enddate1];
    return null;


User-added image

Hope this helps you!
Best Regards,
Kunal Purohit 4Kunal Purohit 4
What is "a" in a.From_date__c?  is From_date__c is field of record?