SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Select with date and hour interval

    hi there, hope in your help.

    I need to extract from my table:
    1. all the rows of the previous day;
    2. all the rows of the current day until 6 o'clock in the morning;

    I tried this query but the output is null, I have two rows with previous day.
    Can you help me?
    thank you.
    Code:
    SELECT
    	*
    FROM
    	mytable
    WHERE
    	myDate BETWEEN DATE_SUB(
    		CURRENT_DATE (),
    		INTERVAL 1 DAY
    	)
    AND (
    	CURRENT_DATE ()
    	AND myHour < '06:00'
    );
    Thanks you very much for your help
    I'm really happy for your quickly answer.
    Good bye

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Try
    Code:
    SELECT
    	*
    FROM mytable
    WHERE myDate = DATE_SUB(CURRENT_DATE (), INTERVAL 1 DAY)
    OR (     myDate = CURRENT_DATE ()
         AND myHour < '06:00'
       )

  3. #3
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot!
    Thanks you very much for your help
    I'm really happy for your quickly answer.
    Good bye

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    it needs to be said that having two separate columns for date and time is usually a lot worse (for the resulting complexity in sql) than a single datetime column
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    it needs to be said that having two separate columns for date and time is usually a lot worse (for the resulting complexity in sql) than a single datetime column
    many thanks for suggestion!
    Thanks you very much for your help
    I'm really happy for your quickly answer.
    Good bye


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
  •