How to Get the Current System Time using SOQL
You don't need to use SOQL. You can just create a new DateTime and set it to the current date and time like below
DateTime myDateTime = system.now();
Or if you only want the date, then
Date myDate = system.today();
Alternatively, there is a method System.currentTimeMillis() that returns the current time in milliseconds.
From that, you can create a new DateTime with the DateTime.newInstance(Long) method:
Long longtime = System.currenTimeMillis();
DateTime dt = DateTime.newInstance(longtime);
If you cannot use Apex, and need to use SOQL only, then binding is not allowed. Which means you cannot use system.now();
With that in mind, you can use Date Literals, such as YESTERDAY
, TODAY
, TOMORROW
, and so on.
Eg:
SELECT CreatedDate FROM Account WHERE CreatedDate <= TODAY
SELECT CreatedDate FROM Account WHERE CreatedDate <= YESTERDAY