+ Start a Discussion
Justin DohJustin Doh 

How to display today's date in SOQL

I am new to SOQL. 
I am trying to write a simple query where it basically says "SELECT aDate from TableA where aDate is less than today's date"
The data field for aDate is TEXT(10), and it displays as 2017-02-28.
I googled around, but somehow, it would not retrieve the output as I expected.
I found something like using TODAY, TODAY(), SYSTEM.TODAY() etc.

If I do this this works.
SELECT aDate from TableA where aDate < '2017-02-28'

What is expression that says today's date in the text format?

Thanks in advance.

 
Best Answer chosen by Justin Doh
Vinuthh SVinuthh S
Hi Justin

I think this is the only solution because in the Text Field < and > wont work, if you change the Text to Date or DateTime it will work

Thanks
Vinuthh S

All Answers

ArreyYaarArreyYaar
Hi Justin,

You don't need a SOQL per se. If you are on a VF page and trying to retrieve and show Todays date you can use something lile this, it will be in a 
Today's date: {!YEAR() +'-'+MONTH()+'-'+DAY()}

But if you still want it in a SOQL query, I suggest changing the aDate field to that of Date type so that you could use 
Select Id, Name, aDate from TableA where aDate<TODAY

Please let me know for anymore queries. Else, please can you mark this as the solution. Thanks!
Vinuthh SVinuthh S
Hi Justin 

You have to change the aDate field type to Date or DateTime Type, because 2017-02-28 is considered as Text not as Date.Change the field type to Date and use the Same query it will work.

Thanks 
Vinuthh S
Justin DohJustin Doh
Hi Thank you for your replies.
Is there any other solution beside changing the data type from TEXT(10) to  DateTime type?
Vinuthh SVinuthh S
Hi Justin

I think this is the only solution because in the Text Field < and > wont work, if you change the Text to Date or DateTime it will work

Thanks
Vinuthh S
This was selected as the best answer