Henry Olive 5 Posted February 5, 2021 (edited) 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 February 5, 2021 by Henry Olive Share this post Link to post
Stano 143 Posted February 5, 2021 (edited) 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 February 5, 2021 by Stano Share this post Link to post
Jeff Overcash 2 Posted February 12, 2021 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 Posted February 12, 2021 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
Henry Olive 5 Posted February 13, 2021 Thank you so much Stano, Jeff, EmailX45 Share this post Link to post
Guest Posted February 23, 2021 (edited) On 2/13/2021 at 8:15 AM, Henry Olive said: Thank you so much Stano, Jeff, EmailX45 https://blogs.embarcadero.com/user-defined-functions-with-interbase/ http://freeadhocudf.org/index_eng.html Edited February 23, 2021 by Guest Share this post Link to post