#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    25
    Rep Power
    0

    Compare Date/Remove Date


    Hey guys, I was wondering how do you compare a date from a particular sql table to todays date and remove it from the table?
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    which database system are you using?

    also, what does "remove it from the table" mean?

    Comments on this post

    • powersoftllc agrees : Great help!
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    25
    Rep Power
    0
    Either mysql or ms sql. I'd prefer the syntax for ms sql but if I get it on mysql I can figure out on ms sql. Thank you
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    Originally Posted by powersoftllc
    Either mysql or ms sql.
    they are completely different when it comes to date functions

    mysql -- WHERE somedate = CURRENT_DATE

    mssql -- WHERE somedate = DATE(GETDATE())

    what does "remove it from the table" mean?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    25
    Rep Power
    0
    Originally Posted by r937
    they are completely different when it comes to date functions

    mysql -- WHERE somedate = CURRENT_DATE

    mssql -- WHERE somedate = DATE(GETDATE())

    what does "remove it from the table" mean?
    If somedate is past currentdate, dont include somedate in SELECT statement.
  10. #6
  11. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    Originally Posted by powersoftllc
    If somedate is past currentdate, dont include somedate in SELECT statement.
    what would you select instead? NULL?

    a SELECT must always return the exact same number of columns for each row in the result set
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    25
    Rep Power
    0
    we are selecting individual fields so if somedate is past currentdate, if its not, i want all the table info that matches the search condition.
  14. #8
  15. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    Originally Posted by powersoftllc
    we are selecting individual fields so if somedate is past currentdate, if its not, i want all the table info that matches the search condition.
    sorry, you cannot do that
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    25
    Rep Power
    0
    Any reason why?
  18. #10
  19. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    Originally Posted by powersoftllc
    Any reason why?
    because you did not really clarify what you wanted

    i just had another thought...

    perhaps you meant this --
    Code:
    SELECT *
      FROM daTable
     WHERE somedate <= CURRENT_DATE
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    25
    Rep Power
    0
    Oh PERFECT I think that's it. Will try it. Although I think what I meant was SELECT whatevervaluesINeed
    FROM my_table
    WHERE somedate <= CURRENT_DATE

    I will try both and post my results. Thank you again.

IMN logo majestic logo threadwatch logo seochat tools logo