SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    select only date where belong to three months

    Hi..

    I just want to know what would be the query if I just want to select date is the first 3 months.

    for example.

    I have month in dates
    sampe:
    ETD = April, May, June, July, August.

    And now I just want to select is the first 3 months and its (April, May, June).



    Thank you

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    use SUBSTRING_INDEX function
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    use SUBSTRING_INDEX function
    How?

    Thank you

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)

  5. #5
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    select the first three consecutive months

    Hi..

    I need help in selecting first 3 Consecutive Months from my table ETD which type is Date.

    for example in my ETD:

    2012-04-01
    2012-04-01
    2012-04-05
    2012-04-08
    2012-04-08
    2012-05-01
    2012-05-01
    2012-05-05
    2012-05-08
    2012-05-08
    2012-06-01
    2012-06-01
    2012-06-05
    2012-06-08
    2012-06-08
    2012-07-01
    2012-07-01
    2012-07-05
    2012-07-08
    2012-07-08
    2012-08-01
    2012-08-01
    2012-08-05
    2012-08-08
    2012-08-08


    Now from this ETD data:

    I need to select only are:
    (from April - June)
    2012-04-01
    2012-04-01
    2012-04-05
    2012-04-08
    2012-04-08
    2012-05-01
    2012-05-01
    2012-05-05
    2012-05-08
    2012-05-08
    2012-06-01
    2012-06-01
    2012-06-05
    2012-06-08
    2012-06-08

    Thank you

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,016
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Code:
    SELECT daTable.etd
      FROM ( SELECT MIN(etd) - INTERVAL DAYOFMONTH(etd) - 1 DAY AS firstday
               FROM daTable ) AS m
    INNER
      JOIN daTable
        ON daTable.etd >= m.firstday
       AND daTable.etd  < m.firstday + INTERVAL 3 MONTH
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •