Re: Number of days in a month - Mailing list pgsql-novice

From Josh Berkus
Subject Re: Number of days in a month
Date
Msg-id web-521804@davinci.ethosmedia.com
Whole thread Raw
In response to Number of days in a month  (Michael Klatt <mdklatt@ou.edu>)
List pgsql-novice
Michael,

> Is there a PostgreSQL function to return the number of days in a
> month?

No.  You could fairly easily write a SQL function to do this, though.
The function should do the following:

1. Accept a year and month as input.
2. Create a DATETIME value that is the 1st day of that year and month
3. Add one month to the datetime value.
4. Subtract one day from the datetime value
5. Extract the day of the month from that datetime value.
6. The day of the month is your number of days.

For the tools to do this, see:
http://www.postgresql.org/idocs/index.php?functions-datetime.html
and
http://techdocs.postgresql.org/techdocs/faqdatesintervals.php

-Josh Berkus



______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

pgsql-novice by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: Storing number '001' ?
Next
From: Jason Earl
Date:
Subject: Re: Storing number '001' ?