For example, let’s consider a table named “users” with records containing the name, address, and other information of a new user. More importantly, the table contains the attribute “created_date” which holds the time and date of when the user joined. The following shows how we can select the users who have joined in the past 24 hours in order of earliest to most recent:
This is all done using a
WHERE clause. We are selecting the records who have a created date that lies between the current time and 24 hours before the current time. A different query which accomplishes the same thing could look something like this:
In this case, we are selecting the records who have a created date which is from 24 hours before the current time up to the current time. In either case, we obtain the same result. There are similar PostgreSQL functions that can help assist in this task, and you can refer here for more information on these Date/Time functions. We note that if we want to change the period of time to search, we would edit the WHERE clause to represent the desired time frame to search.