kamal Aliyu
kamal Aliyu

Reputation: 77

Get return data of field date as current date

I want to return all entries that are entered today does not matter the time I use this to insert

INSERT INTO hangfire.job(stateid, statename, invocationdata, arguments, createdat, expireat, updatecount)
VALUES (44, 'Schedule', 'Test Invocation data', 'Test arguments', now()::timestamp, null, 0);

And use this to retrieve the data but it returns nothing only the fields

SELECT * From hangfire.job WHERE createdat = now()::timestamp;

Upvotes: 0

Views: 34

Answers (1)

user330315
user330315

Reputation:

A timestamp contains a time (as the name indicates), if you want to ignore that time, use a date:

SELECT * 
From hangfire.job 
WHERE createdat::date = current_date;

If you have an index on createdat the above will not use that index. If you need that for performance reasons, use a range condition:

SELECT * 
From hangfire.job 
WHERE createdat >= current_date
  AND createdat < current_date + 1;

Upvotes: 1

Related Questions