I always had issues with SOQL Query utilizing dates in particular. So I wanted to share some tips and tricks on writing SOQL queries using some Built in Date Functions...
Now you do your query in 2 ways:
1. Specify a date in your query such as
Select Id,CreatedDate from Account where CreatedDate=DateValue(2008-02-05)
This will return all Id's for all the Account Object that were Created 2008-02-05.
2. Do it with a Fixed Expression or Built in Function such as:
Select Id, CreatedDate from Account where CreatedDate = YESTERDAY
This will return all Id's for the Account Object that were Created yesterday.
This is called a Date Literal.
Now before we go on:
You must know the Syntax for Date in Force.com :
YYYY-MM-DD
For DateTime the Syntax is as follows:
YYYY-MM-DDThh:mm:ss+hh:mm 2009-02-24T23:01:01+01:00
YYYY-MM-DDThh:mm:ss-hh:mm 2009-02-24T23:01:01-08:00
YYYY-MM-DDThh:mm:ssZ 2009-02-24T23:01:01Z
So Lets go into Date Literals: I took this off from the Salesforce.com Api docs...
The link is: http://www.salesforce.com/us/developer/docs/api/index.htm
Go to search and type in Date Literals... This should come up.(See Below)




This comment has been removed by the author.
ReplyDeletei want to fetch all the records created in between two particular dates and time too.
ReplyDeletehow can i use SOQL.
Thanks