MySQL Forums
Forum List  »  Knowledge Base

Re: days in a month
Posted by: Mark Nessfield
Date: August 14, 2009 01:34AM

Hi,
I think you have two main elements to solve here. The first is establishing how many days in a particular month. Here's how you do it for the current month:

select day(last_day(now()));

You should be able to adapt this to the month you are looking at, by changing the now() element.

As for selecting a row for each day, one way is by using a join to a table that has a column with values that increment by 1 eg 1, 2, 3, 4, 5 and putting in the Where clause "Where col_val <= last_day_value Order by col_val"

Although this is not a complete answer (you'll gain more by working out exactly how to implement the solution) I hope it's of use.

----------------------------------------------------------------------------------
Follow my progress with mysql (English/Spanish) at my blog http://www.oxfordtechnotes.co.uk/sqlblog/blog4.php

Options: ReplyQuote


Subject
Views
Written By
Posted
3553
June 17, 2009 08:31AM
Re: days in a month
3054
August 14, 2009 01:34AM
3304
August 18, 2009 06:04AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.