Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Help me in getting no. of days in a month

Author  Topic 

kadiyalabindu
Starting Member

7 Posts

Posted - 2005-09-29 : 03:29:41
Hi All,

Is there any function to get the number of days in a particular month.
For example,
In January , Number of days are 31


Can anyone solve me in getting the output.

Thk u

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-29 : 07:18:22
Try this

SELECT monthname(month(dateCol)), Day(DateAdd("m",1,dateCol)- Day(DateAdd("m",1,dateCol)))
from yourTable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-09-29 : 10:12:13
I got this error:
Server: Msg 195, Level 15, State 10, Line 3
'monthname' is not a recognized function name.


This works for me:
select	[Days in Month] =datediff(day,
dateadd(month,datediff(month,0,dt),0),
dateadd(month,datediff(month,0,dt)+1,0))
from
(select dt = convert(datetime,'2004/02/29') ) a


quote:
Originally posted by madhivanan

Try this

SELECT monthname(month(dateCol)), Day(DateAdd("m",1,dateCol)- Day(DateAdd("m",1,dateCol)))
from yourTable

Madhivanan

Failing to plan is Planning to fail



CODO ERGO SUM
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-29 : 10:14:13
This is Access Forum and I think my query works in Access

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2005-09-29 : 10:15:41
>>>>> I got this error:
Server: Msg 195, Level 15, State 10, Line 3
'monthname' is not a recognized function name.


Yes, but did you run madhivanans code in Access or SQL server?


Duane.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-09-29 : 10:20:26
Sorry, I forgot the forum.

If you want to do it in SQL Server, or a pass-through query, my code will work, but I don't think it's good for Access.





CODO ERGO SUM
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-29 : 10:22:56
>>Sorry, I forgot the forum.

No problem MVJ

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -