Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2007
    Posts
    56

    Unanswered: checking date greater then today

    i want to use a query that checks for the given date is greater then today i have written something like this
    select convert(Datetime , isNull(offsel.custom0, convert(datetime, '1/1/1900', 105)),111) from let_ext_offering_session offsel

    here this custom0 can be null so the above query replaces 1900/1/1 in the value is null but if it is not null then how do i check if the input date is greater then today.

    Thanks

  2. #2
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    Try
    Code:
    SELECT *
    FROM DaTable
    WHERE DaDate is not null AND
    	DaDate < GETDATE()
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Its not necessary to check for null in this case. Null will never satisfy the criteria of being greater than or less than getdate().

    Code:
    select	*
    from	let_ext_offering_session offsel
    where	datediff(day, getdate(), offsel.custom0) >=1
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    blindman, i'm ashamed of you, violating your own coding conventions like that

    what you meant to write was of course
    Code:
    select	*
    from	let_ext_offering_session 
    where	datediff(day, getdate(), let_ext_offering_session.custom0) >=1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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