Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread days in a month
Tue, Jul 8 2014 7:52 PMPermanent Link

ClockOn

does anyone know how to calculate how many days in a month?
including leap years Wink

dont think i could see a function for it.
Wed, Jul 9 2014 7:43 PMPermanent Link

ClockOn

Figured out one way, just to set a date range and deduct one from the other, passing in the month required, in the example its just hard coded, seems to work.

Feb 2014 = 28 days:

select cast('2014-' + '3' + '-01' as Date) - cast('2014-' + '2' + '-01' as Date) from Table1
Thu, Jul 10 2014 3:58 AMPermanent Link

Matthew Jones

ClockOn wrote:

> Figured out one way, just to set a date range and deduct one from the
> other, passing in the month required, in the example its just hard
> coded, seems to work.
>
> Feb 2014 = 28 days:
>
> select cast('2014-' + '3' + '-01' as Date) - cast('2014-' + '2' +
> '-01' as Date) from Table1

Clever! I was pondering this (not having done it before) and thinking
of doing the "one less than 2014-03-01" but thinking it would be
complex for januaries etc. and getting the day part out. Yours is much
better.

--

Matthew Jones
Thu, Jul 10 2014 7:21 PMPermanent Link

ClockOn

That is another way Matthew, thanks for the idea works just as easy, i like it:


extract(day from cast('2014-03-01' as Date) - 1) from Table1
Image