Rahul
Rahul

Reputation: 1005

postgresql count all entries created on a particular date?

I want to count all entries created on a particular date in postgresql. The table has a created_date field which of type time stamp without time zone , One of the entries in created_date looks like this 2020-08-18 12:26:22.641.

select count(*) from table where created_date='2020-08-18*' This is what i try but that does not work.

How can i count is there something like contain or regex match for this scenario?? Thanks!!

Upvotes: 1

Views: 58

Answers (1)

user330315
user330315

Reputation:

The most efficient way is to use a range condition:

select count(*)
from the_table
where created_date >= date '2020-08-18'
  and created_date < date '2020-08-19';

Another option is to cast the timestamp to a date value:

select count(*)
from the_table
where created_date::date = date '2020-08-18'

Upvotes: 3

Related Questions