find month days

2019-08-18 02:27发布

问题:

I need to find how many days have in this month which we can find with today's date

select to_number(to_date('01.02.2011')-to_date('01.01.2011')) from dual; 

not this query Have any other queries?

回答1:

You can do it with a trunc(<date>, 'mm') (which returns the first day of the month) and an add_months(<date>,1) which add one month to a particular day. So, in order to find out how many days the month has in which we currently are (i.e. sysdate), you could go with something like:

select  
  add_months(trunc(sysdate, 'mm'),1) - trunc(sysdate, 'mm') 
from 
  dual;


回答2:

select extract(day from last_day(sysdate)) from dual

?



回答3:

select DateDiff(Day,GETDATE(),DateAdd(month,1,GETDATE()))


标签: sql oracle10g