Days in Month
Hello, is there a MySQL function to determine the total days of any given month, IE if current month is April, is there a function or query to find the total days of the month? TIA, Mike(mickalo)Blezien === Thunder Rain Internet Publishing Providing Internet Solution that Work === -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: Days in Month
Mike, Maybe : LAST_DAY(date) Takes a date or datetime value and returns the corresponding value for the last day of the month. Returns NULL if the argument is invalid. mysql SELECT LAST_DAY('2003-02-05'); - '2003-02-28' mysql SELECT LAST_DAY('2004-02-05'); - '2004-02-29' mysql SELECT LAST_DAY('2004-01-01 01:01:01'); - '2004-01-31' mysql SELECT LAST_DAY('2003-03-32'); - NULL -Original Message- From: Mike Blezien [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 04, 2006 2:48 PM To: MySQL List Subject: Days in Month Hello, is there a MySQL function to determine the total days of any given month, IE if current month is April, is there a function or query to find the total days of the month? TIA, Mike(mickalo)Blezien === Thunder Rain Internet Publishing Providing Internet Solution that Work === -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: Days in Month
Mike Blezien [EMAIL PROTECTED] wrote on 04/04/2006 02:47:50 PM: Hello, is there a MySQL function to determine the total days of any given month, IE if current month is April, is there a function or query to find the total days of the month? TIA, Mike(mickalo)Blezien === Thunder Rain Internet Publishing Providing Internet Solution that Work === Well, the first place I would have looked is in the manual... http://dev.mysql.com/doc/refman/4.1/en/index.html Having skimmed through it at least once (something I recommend that everyone does), I know there is a section describing all of the functions that work with date and time values... http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html where I found a function to return exactly what you were looking for... http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#id2691432 Respectfully, Shawn Green Database Administrator Unimin Corporation - Spruce Pine
mysql return days in month?
Hi all, Can anyone help? I want to know if there is an easy way to return the number of days in a month from mysql. Ideally there would be a function that did the following... mysql SELECT DAYSINMONTH('2002-10'); +---+ | DAYINMONTH('2002-10') | +---+ |31 | +---+ 1 row in set (0.00 sec) But there isn't Anyone got any ideas before I go off and do it in perl? Thanks, Andrew Sql,query - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: mysql return days in month?
It's not all that elegant, but how about this: Mysql SELECT date_format(date_add('2002-10-01', interval -1 day), %d); Basically, take the first day of the month, subtract one and figure out what the day number is. -- Jason On 11/18/02 9:02 AM, Andrew Braithwaite [EMAIL PROTECTED] wrote: Hi all, Can anyone help? I want to know if there is an easy way to return the number of days in a month from mysql. Ideally there would be a function that did the following... mysql SELECT DAYSINMONTH('2002-10'); +---+ | DAYINMONTH('2002-10') | +---+ |31 | +---+ 1 row in set (0.00 sec) But there isn't Anyone got any ideas before I go off and do it in perl? Thanks, Andrew Sql,query - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: mysql return days in month?
* Andrew Braithwaite Can anyone help? I want to know if there is an easy way to return the number of days in a month from mysql. Ideally there would be a function that did the following... mysql SELECT DAYSINMONTH('2002-10'); +---+ | DAYINMONTH('2002-10') | +---+ |31 | +---+ 1 row in set (0.00 sec) But there isn't Anyone got any ideas before I go off and do it in perl? You can start with the first day of the _next_ month, and go 1 day back...: mysql select dayofmonth('2002-11-01' - interval 1 day); +---+ | dayofmonth('2002-11-01' - interval 1 day) | +---+ |31 | +---+ 1 row in set (0.01 sec) -- Roger - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
RE: mysql return days in month?
Thanks for solving this all, I have do something ugly because I only have the -mm (3rd party DB) which ends up like this: Mysql select dayofmonth((concat('2004-02','-01') + interval 1 month) - interval 1 day); Urrggg ;) Still, much more graceful (and more future proof) than what I just came up with: select case when (right('2002-04',2) = '02') then 28 when ('%09%04%06%11%' regexp right('2002-04',2)) then 30 else 31 end as daysinmonth; lol Thanks Andrew Sql,query * Roger Baklund You can start with the first day of the _next_ month, and go 1 day back...: mysql select dayofmonth('2002-11-01' - interval 1 day); - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: mysql return days in month?
Not all Feb. has 28 days. It depends on whether it is a lunar year or not. So Some Feb. will have 28 days and some have 29 days. Pae - Original Message - From: Andrew Braithwaite [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: 'Roger Baklund' [EMAIL PROTECTED] Sent: Monday, November 18, 2002 7:52 AM Subject: RE: mysql return days in month? Thanks for solving this all, I have do something ugly because I only have the -mm (3rd party DB) which ends up like this: Mysql select dayofmonth((concat('2004-02','-01') + interval 1 month) - interval 1 day); Urrggg ;) Still, much more graceful (and more future proof) than what I just came up with: select case when (right('2002-04',2) = '02') then 28 when ('%09%04%06%11%' regexp right('2002-04',2)) then 30 else 31 end as daysinmonth; lol Thanks Andrew Sql,query * Roger Baklund You can start with the first day of the _next_ month, and go 1 day back...: mysql select dayofmonth('2002-11-01' - interval 1 day); - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
RE: mysql return days in month?
Exactly... That's why Rogers solution is good (and future proof) and my solution is bad! I was illustrating that point by using 2004-02 in the example.. Andrew -Original Message- From: Pae Choi [mailto:[EMAIL PROTECTED]] Sent: 18 November 2002 22:56 To: Andrew Braithwaite; [EMAIL PROTECTED] Cc: 'Roger Baklund' Subject: Re: mysql return days in month? Not all Feb. has 28 days. It depends on whether it is a lunar year or not. So Some Feb. will have 28 days and some have 29 days. Pae - Original Message - From: Andrew Braithwaite [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: 'Roger Baklund' [EMAIL PROTECTED] Sent: Monday, November 18, 2002 7:52 AM Subject: RE: mysql return days in month? Thanks for solving this all, I have do something ugly because I only have the -mm (3rd party DB) which ends up like this: Mysql select dayofmonth((concat('2004-02','-01') + interval 1 month) Mysql - interval 1 day); Urrggg ;) Still, much more graceful (and more future proof) than what I just came up with: select case when (right('2002-04',2) = '02') then 28 when ('%09%04%06%11%' regexp right('2002-04',2)) then 30 else 31 end as daysinmonth; lol Thanks Andrew Sql,query * Roger Baklund You can start with the first day of the _next_ month, and go 1 day back...: mysql select dayofmonth('2002-11-01' - interval 1 day); - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php