How do I select between 1st day of the current month and the 1st day of the following month (from current month) in postgres

user17170756

SELECT tbl.createdate > '20211001' and tbl.createdate < '20211101'

I need the dates in the '' to change depending on the date the query is run. For example if I schedule it to run in November it would be SELECT tbl.createdate > '20211101' and tbls.createdate < '20211201'

and if I run it in December it would be SELECT tbl.createdate > '20211201' and tbl.createdate < '20220101'

I need the query to run without user changing the dates.

Edouard H.

Your can use the date_trunc() function, see the manual. The result is :

SELECT *
FROM tbl 
WHERE tbl.createdate > date_trunc('month', Now()) 
  and tbl.createdate < (date_trunc('month', Now()) + interval '1 month')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make it to select from 1st day every month

How to get 1st calendar day of the current and next month based on a current date variable

How do I run a script for 1st working day of every month in cron?

Get 1st of current month and year

SQL/VBA: How to group by a fiscal year starting from a day other than 1st day of month

Is there an easy way to create a vector following the pattern: 1st day of the month, last day of the month, 1st day of the month etc.?

Pandas: convert date in month to the 1st day of next month

How do I code a dynamic NetSuite date range that begins the 1st day of the month (4 months ago) and ends the last day of last month?

How can I get the last 12 months from the current date PLUS extra days till 1st of the last month retrieved

jQuery datepicker will not allow selecting dates when month has 31 days and select 1st day of month

sql return 1st day of each month in table

Day of Week in Month (numeric). The example is for the 1st Wednesday in April

SSRS How to get 1st date in month with a 1 day lag?

Date query to select 1st to 3rd of current month and compare against a column

SQL to calculate difference from 1st day of Month to Date specified

Material UI Datepicker to start from 1st day of next month

Ruby: number of times a specific day of the month (eg. 1st of each month) occurs between two dates

How to schedule task which will execute every 1st day of month and update a value in Firebase realtime database

How to schedule a task to run every weekday except on the 1st day of the month

count the number of days of current month from day 1 until yesterday

Get 1st day of the Current Quarter

Get the current number of the month of the financial year (Financial Year = from 1st of April to 31st of March)

MySQL - trying to select a range from the first day of previous month at midnight, to the first day of the current month at midnight

Date Scalar Function to display 1st day or last day of the Month

how may i select the time interval from last month ?, and it must also be between 1pm from last day of the last month till midday of the actual day

How can I increment month number if given day is last day of current month?

Current Sql Date in Spring StoredProcedure Causes ORA-01847: day of month must be between 1 and last day of month

How to get the first day of the current week and month?

How to get last day of current month?