CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2003
    Posts
    593

    Comparing dates in SQL

    I have a very annoying problem that probably has a simple answer but I just can't see it. In the Member table in my database is an field DateJoined representing the date a particular member joined. What I want to do is perform an update only to those members that joined after a specific date. My problem is that I can't seem to get the SQL command correct to compare the dates. Here is the full statement I have
    Code:
    UPDATE Member SET Balance = Balance+550 WHERE (DateJoined > 9/3/2004);
    The SQL compiles fine, and it runs without error. The problem is that it updates every record in my table, not just the ones after 9/3/2004. There are records in there with dates from 2003 in there, and in fact only one record is after the date above (the reason I picked it to perform tests with). Is my statement wrong, and if so how should I fix it? (If it's of any consequence i'm using MSAcess).

    Thanks in advance, Mike.

  2. #2
    Join Date
    Jun 2001
    Location
    Mi
    Posts
    1,249
    # signs ... Date literals need to be surrounded by # signs ...

  3. #3
    Join Date
    Dec 2003
    Posts
    593
    i tried that, but now its updating no rows at all....

  4. #4
    Join Date
    Dec 2003
    Posts
    593
    ok, i've sorted it....it was reading the date in a different format to the way I expected. Here (in england) we right dates in the format dd/mm/yy but it was reading it in the format mm/dd/yy. Such a simple problem but it's taken me all night to figure it out!

  5. #5
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210
    you can also use the YYYYMMDD format to forget about date issues.

    like :
    20030401

  6. #6
    Join Date
    Dec 2003
    Posts
    593
    i'll remember that in future, thanks As for now, i've finally got it all working.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured