+ Start a Discussion
minkeshminkesh 

how to fiter created date as it is working in standard product filter?

Hello ,

             I have one requirement to make custom product functionality so i am making filter for that but how to check it with created date in query? createdDate only allows date time format and their standard product allows following formats i.e.

 

                   Valid date format 3/10/2011 or 3/10/2011 1:17 PM

 

so how can i do as they did? reply me fast if anyone knows ?

 

Thank you,

Minkesh Patel

bob_buzzardbob_buzzard

I've found that the easiest way to query against created date is to create a local DateTime variable representing the point in time and bind that in to the query.

 

E.g.

 

 

DateTime dt=System.now();
List<Contact> conts=[select id, Name from Contact where createddate<:dt];

 

 

hgarghgarg

I have one more suggestion, that is working for us for filtering DateTime fields.

You can make your date string in the format: YYYY-MM-DDThh:mm:ssZ

The datetime works directly in soql in this format.

minkeshminkesh

Hello Bob,

                    I know that we can do it that way but i am building my SOQL query as a String and i if user enters in MM/DD/YYYY format how we will set it into the query? So i have used like MM/DD/YYYYT00:00:00Z to MM/DD/YYYYT23:59:59Z. just appended that time and checking that created date is in between of this two than we got the date ? Is It right way ?

bob_buzzardbob_buzzard

According to the docs at: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_dateformats.htm

 

SOQL expects the date separators to be '-', e.g.

 

YYYY-MM-DDT00:00:00Z

 

 

minkeshminkesh

Hello Bob,

                   yes that is true but sorry i forgot to tell you that user will enter date in that format and in controller i have written logic and replaced it with '-' sign.

minkeshminkesh

Hello Bob,

                    I am planning to give certification Dev(401). So if u have any material or some document from which i can prepare for that exam.

bob_buzzardbob_buzzard

I found the Force.com Developer Guide to be invaluable when preparing for this exam.  I spent the weekend before working through all of the examples.  It also helps to be working on the platform for a while.