Professional Web Applications Themes

date arithmatic - MySQL

Hey all. I just started usng mysql, and need a bit of help arriving at the following select date, datefunctionhere from table; DATE | DATE_ADD_FUNCTION_HERE 28/02/2006 | 31/03/2006 31/03/2006 | 30/04/2006 30/04/2006 | 31/05/2006 As you can see from the above pretend sql and result-set, i basically want to arrive (using the date functions) at the end of the month of the following month given a current date. The problem is when you use the date_add() function on 28 february you will only get to the 28th of march instead of 31st of march etc. sorry if this doesnt make ...

  1. #1

    Default date arithmatic

    Hey all.

    I just started usng mysql, and need a bit of help arriving at the
    following

    select date, datefunctionhere
    from table;

    DATE | DATE_ADD_FUNCTION_HERE
    28/02/2006 | 31/03/2006
    31/03/2006 | 30/04/2006
    30/04/2006 | 31/05/2006

    As you can see from the above pretend sql and result-set, i basically
    want to arrive (using the date functions) at the end of the month of
    the following month given a current date. The problem is when you use
    the date_add() function on 28 february you will only get to the 28th of
    march instead of 31st of march etc.

    sorry if this doesnt make sense, but any help would be appreciated.

    cheers guys

    Jared

    jared.pohl@gmail.com Guest

  2. #2

    Default Re: date arithmatic


    <jared.pohl> schreef in bericht
    news:1148558452.463381.90720j33g2000cwa.googlegro ups.com...
    > Hey all.
    >
    > I just started usng mysql, and need a bit of help arriving at the
    > following
    >
    > select date, datefunctionhere
    > from table;
    >
    > DATE | DATE_ADD_FUNCTION_HERE
    > 28/02/2006 | 31/03/2006
    > 31/03/2006 | 30/04/2006
    > 30/04/2006 | 31/05/2006
    >
    > As you can see from the above pretend sql and result-set, i basically
    > want to arrive (using the date functions) at the end of the month of
    > the following month given a current date. The problem is when you use
    > the date_add() function on 28 february you will only get to the 28th of
    > march instead of 31st of march etc.
    >
    > sorry if this doesnt make sense, but any help would be appreciated.
    >
    > cheers guys
    >
    > Jared
    >
    at: [url]http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html[/url]

    if find:
    a.. 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
    a..


    Luuk Guest

Similar Threads

  1. JSObject returns wrong date. How can Iextract correct date from digital signature?
    By Hal_Underwood@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 0
    Last Post: February 19th, 01:22 AM
  2. Replies: 1
    Last Post: October 24th, 11:38 AM
  3. Replies: 3
    Last Post: October 21st, 07:13 PM
  4. mysql or php timestamp arithmatic
    By Christian Calloway in forum PHP Development
    Replies: 0
    Last Post: August 25th, 12:06 PM
  5. Replies: 0
    Last Post: August 12th, 04:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139