function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
karthic sankar 9karthic sankar 9 

how to query for date field

Hi All,

I have field with data type date:

How to query based on that field.

select id, Week_Start_Date__c from QAAM_Weekly_Planner__c where Week_Start_Date__c  := 6/07/2020

I get unknown parse error.

Kindly help.
Best Answer chosen by karthic sankar 9
Maharajan CMaharajan C
Hi Karthic,

Use the below Query:

select id, Week_Start_Date__c from QAAM_Weekly_Planner__c where Week_Start_Date__c  =  2020-07-06

The format is YYYY-MM-DD

Thank,
Maharajan.C

All Answers

Maharajan CMaharajan C
Hi Karthic,

Use the below Query:

select id, Week_Start_Date__c from QAAM_Weekly_Planner__c where Week_Start_Date__c  =  2020-07-06

The format is YYYY-MM-DD

Thank,
Maharajan.C
This was selected as the best answer
karthic sankar 9karthic sankar 9
Hi Maharaj

THanks for your reply. Can you also tell me how to covert string to date.

I have string in this format 01-01-2020
I need this converted to be date in format 01-01-2020

Reagrds
Karthic 
Maharajan CMaharajan C
You Can use the parse(stringDate) method. Refer the below date class methods.
​​
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_date.htm
karthic sankar 9karthic sankar 9
Hi Maharajan

Thank you but Its not helping me out, can u pls guide me.

Regards
Karthic