Jump to content
Sign in to follow this  
Henry Olive

Interbase Get Days count of a month

Recommended Posts

I wish everyone healthy days.
 

I want to get day count of a month

for example, for january=31 for february=28 (in 4 years it is 29) 

for April=30
 

I tried 

SELECT EXTRACT (DAY FROM current_date) FROM rdb$database
where extract(month FROM current_date)=2

but not correct.
 

Thank You

Edited by Henry Olive

Share this post


Link to post

For Firebird

First Day of The Date:

SELECT CAST(:DATA AS DATE) - EXTRACT(DAY FROM CAST(:DATA AS DATE)) + 1 FROM RDB$DATABASE

LAST DAY OF THE DATE:

SELECT CAST(:DATA AS DATE) - EXTRACT(DAY FROM CAST(:DATA AS DATE)) + 32 -
  EXTRACT(DAY FROM (CAST(:DATA AS DATE) - EXTRACT(DAY FROM CAST(:DATA AS DATE)) + 32)) FROM RDB$DATABASE

 

Edited by Stano

Share this post


Link to post

To get the count of days in a month just subtract (as dates)  the first day of the next month from the first day of this month. Actually, as long as the day is the same from both months that works too so don't have to start with day 1 of the month.

 

select cast('2/1/2021' as date) - cast('1/1/2021' as date) from rdb$database

 

returns 31.

 

select cast('3/15/2020' as date) - cast('2/15/2020' as date) from rdb$database

 

returns 29  for Feb in 20202 etc.

 

Stano's only gives you the dates of the first and last days of the passed in month, you still need to subtract them and add 1 to get the number of days.

Share this post


Link to post
Guest

for while, Interbase (directly) dont have functions for that, then, you can create a user-function-on: stored procedure or a user-dll by Delphi/CBuilder and use it in your database-user-function aggregate. for many others Database too!

 

you see?

 

System.DateUtils is good source this task.

 

hug

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×