Using a date for a datetime field in a SOQL Query [duplicate]
2015-04-14 16:09
976 查看
http://salesforce.stackexchange.com/questions/8896/using-a-date-for-a-datetime-field-in-a-soql-query
activeoldestvotes
activeoldestvotes
5down votefavorite 2 | This question already has an answer here: Using a date for a datetime field in a SOQL Query criteria 2 answers The SF doc explains how to put a Datetime query in a SOQL query. SELECT Id FROM Account WHERE CreatedDate > 2005-10-08T01:02:03Z I need to just put in a date for this query. Something like: SELECT Id FROM Account WHERE CreatedDate > 2005-10-08 But that throws an error. Any ideas? soql
| ||
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask | |||
add a comment |
3 Answers
activeoldestvotesup vote5down voteaccepted | CreatedDate is a datetime field so I guess you would need to specify the time component. Can you do something like where you just append the time portion to be 12 am by default. WHERE CreatedDate > 2005-10-08T00:00:00Z Or you can use Date Literals like WHERE CreatedDate > YESTERDAY For more on date formats and more literal values see, http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_dateformats.htm
| |||
add a comment |
up vote3down vote | If you want to avoid date manipulation with Apex, you could also create a custom date formula field and query off that field. Your formula would look like this:DATEVALUE(CreatedDate) Then just query off your custom field. Let me know if you have any questions.
| ||
add a comment |
up vote3down vote | You'll want to use a DateTime and compute the range, or use date literals.Date inputDate = Date.newInstance(2005,10,8); DateTime refDate1 = DateTime.newInstance(inputDate.year(), inputDate.month(), inputDate.day(), 0, 0, 0); DateTime refDate2 = refDate1.addDays(1); List<Account> accounts = [ select id from Account where createdDate >= :refDate1 and createdDate < :refDate2]; You can bind a date variable into the SOQL Query as well, but the results might not be what you expect. |
5down votefavorite 2 | This question already has an answer here: Using a date for a datetime field in a SOQL Query criteria 2 answers The SF doc explains how to put a Datetime query in a SOQL query. SELECT Id FROM Account WHERE CreatedDate > 2005-10-08T01:02:03Z I need to just put in a date for this query. Something like: SELECT Id FROM Account WHERE CreatedDate > 2005-10-08 But that throws an error. Any ideas? soql
| ||
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask | |||
add a comment |
3 Answers
activeoldestvotesup vote5down voteaccepted | CreatedDate is a datetime field so I guess you would need to specify the time component. Can you do something like where you just append the time portion to be 12 am by default. WHERE CreatedDate > 2005-10-08T00:00:00Z Or you can use Date Literals like WHERE CreatedDate > YESTERDAY For more on date formats and more literal values see, http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_dateformats.htm
| |||
add a comment |
up vote3down vote | If you want to avoid date manipulation with Apex, you could also create a custom date formula field and query off that field. Your formula would look like this:DATEVALUE(CreatedDate) Then just query off your custom field. Let me know if you have any questions.
| ||
add a comment |
up vote3down vote | You'll want to use a DateTime and compute the range, or use date literals.Date inputDate = Date.newInstance(2005,10,8); DateTime refDate1 = DateTime.newInstance(inputDate.year(), inputDate.month(), inputDate.day(), 0, 0, 0); DateTime refDate2 = refDate1.addDays(1); List<Account> accounts = [ select id from Account where createdDate >= :refDate1 and createdDate < :refDate2]; You can bind a date variable into the SOQL Query as well, but the results might not be what you expect. |
相关文章推荐
- 使用Date时,出现"Incorrect datetime value: '' for column 'ordertime' at row 1 Query..."时,该怎么解决呢?
- [原] XAF How to see and edit the time part in the DatePropertyEditor for the System.DateTime property
- Solution for issue of number/currency/date/datetime/boolean type not updating in salesforce.
- 关于EnumerateObjectsUsingBlock和for-in之间的较量
- Unable to find a value for "dwmc" in object of class "java.lang.String" using operator "." (null
- [转]Pass a ViewBag instance to a HiddenFor field in Razor
- Using the WebLogic Maven Plug-In for Deployment:自己build weblogic maven plugin
- A Top-down Approach to Melody Match in Pitch Contour for Query by Humming
- [转]Using Entity Framework (EF) Code-First Migrations in nopCommerce for Fast Customizations
- How to Enable SQL_TRACE for Another Session or in MTS Using Oradebug(文档 ID 1058210.6)
- Using UTF-8 as the internal representation for strings in C and C++ with Visual Studio
- Using lp to test report printing in Unix for Apps
- How to format datetime & date in Sql Server 2005
- How do I Check for Duplicate Items in a ListView?
- omitNorms for field in solr schema
- Using GET_GROUP_SELECTION For Record Groups in Oracle Forms
- 文献综述——In-Situ Visualization in Fluid Mechanics using Catalyst: A Case Study for Code Saturne
- java.lang.RuntimeException: Date pattern must be set for column update_time in the schema of component
- ALV Styles in Field catalogue using OOPS
- enumerateObjectsUsingBlock 、for 、for(... in ...) 的差别 & 性能測试