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
出力用出力用 

SOQL Date Literals

Hello.I am new using SFDC and i have a problem now.

I want to select some data that was created 14 days ago. so i wrote soql like this:
Select Id, CreatedDate FROM ***** WHERE CreatedDate < Last_N_DAYs:14 order by CreatedDate DESC
for example today is 19th so i want to get the date before 5th, but the latest date i get is 2016-08-03T23:34:01.000+0000
FYI i am in UTC 9 time zone. but it is still not right considering the time zone thing.  

I appriciate if someone can tell me what is wrong with it. thanks.
Rakesh Kumar SainiRakesh Kumar Saini

Hi,

Please try below soqls

SELECT Id FROM Account WHERE CreatedDate < 2016-08-03T01:02:03Z 

OR

SELECT Id FROM Account WHERE CreatedDate < LAST_N_DAYs:60 order by CreatedDate DESC 

Thanks,
Rakesh

~Onkar~Onkar
Hi 

Try this Query 

Select Id, CreatedDate FROM ***** WHERE CreatedDate = Last_N_DAYs:14 order by CreatedDate DESC. Remove ">" operator and use "=" operator.

~Thanks
Onkar
 
出力用出力用
Thanks Rakesh
I want to use this query in a batch file so it can do it for me automaticly every week. so i can not point at just one specific date. and the second query, can you tell me why is it LAST_N_DAYS:60 not any other numbers?
出力用出力用
Thanks Onkar
by using "=", i think i will get all date from last 14 days. but i want the data which was created 14 days ago and older.
which is like "~14 days ago", not "14 days ago ~now".
do you have any ideas?
 
~Onkar~Onkar

Hi,

Can you just let me know your ORG Time zone. 

~Onkar Kumar

出力用出力用
Hi, Onkar

It's GMT+09:00. 
Thank you.