Using a date for a datetime field in a SOQL Query [duplicate]
来源:互联网 发布:厉害的淘宝差评怎么写 编辑:程序博客网 时间:2024/06/05 11:32
http://salesforce.stackexchange.com/questions/8896/using-a-date-for-a-datetime-field-in-a-soql-query
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 IdFROM AccountWHERE CreatedDate > 2005-10-08T01:02:03Z
I need to just put in a date for this query. Something like:
SELECT IdFROM AccountWHERE CreatedDate > 2005-10-08
But that throws an error. Any ideas?
marked as duplicate by Ralph Callaway, Daniel Blackhall, eyescream, Saariko Feb 28 '13 at 8:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
3 Answers
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
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.
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 Accountwhere createdDate >= :refDate1and createdDate < :refDate2];
You can bind a date variable into the SOQL Query as well, but the results might not be what you expect.
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 IdFROM AccountWHERE CreatedDate > 2005-10-08T01:02:03Z
I need to just put in a date for this query. Something like:
SELECT IdFROM AccountWHERE CreatedDate > 2005-10-08
But that throws an error. Any ideas?
marked as duplicate by Ralph Callaway, Daniel Blackhall, eyescream, Saariko Feb 28 '13 at 8:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
3 Answers
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
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.
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 Accountwhere createdDate >= :refDate1and createdDate < :refDate2];
You can bind a date variable into the SOQL Query as well, but the results might not be what you expect.
- Using a date for a datetime field in a SOQL Query [duplicate]
- query for a List<String> using DBUtils
- [转]Finding a query in UCM using the query builder
- query for a map
- Delphi Question: Proper using of a Record Field/Property in a Class?
- DateTime.Now.Date.AddDays(int a)
- Query index for a table
- get the week in year for a date use javascript
- Using a URDF in Gazebo
- F4 help functionality for a dynpro screen field using the PROCESS ON VALUE-REQUEST statement
- F4 help functionality for a dynpro screen field using the PROCESS ON VALUE-REQUEST statement
- Using a DateTime Picker for ASP.NET MVC 5 with Bootstrap
- How do you remove the duplicate characters in a given string without using any additional buffer.
- How to study in a field
- search for queries utilizing a specific field
- search for queries utilizing a specific field
- Check if a table or field exists in a database
- delete duplicate rows in a table
- 八数码问题
- eclipse远程调用debug出现 Failed to connect to remote VM because of unknown hostFailed to connect to remote
- 字符串数据类型与其他类型之间的转换
- 今天开博!
- Vim命大全令
- Using a date for a datetime field in a SOQL Query [duplicate]
- Linux高性能服务器编程---服务器程序规范
- 关于URL编码
- python os.path模块
- FlashFXP 连接出现 530 Login incorrect 错误的解决方法
- Mysql入门学习
- 知名OJ
- Android性能优化典范
- Hibernate的LockMode(悲观锁和乐观锁)