SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: sql SELECT query problem, using dates

Hybrid View

  1. #1
    SitePoint Zealot willmoss's Avatar
    Join Date
    Apr 2002
    Location
    London, England
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry sql SELECT query problem, using dates

    Can anyone help me? This thing is driving me up the wall!

    I spent all yesterday afternoon working out how to create a new user in Microsoft SQL (use stored procedure "sp_adduser" for anyone who finds themselves in this situation!) then, when I logged in as this new user, the damned thing started giving me grief executing a SELECT query using dates...



    I am trying to execute this query:

    Code:
    SELECT * FROM meetings WHERE [date] > '15/09/2004 15:00:07' AND [date] < '15/11/2004 15:00:07';
    .. and I get the following error:


    Code:
    Microsoft OLE DB Provider for SQL Server error '80040e07' 
     
    The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.


    So, I tried removing the apostrophes:



    Code:
    SELECT * FROM meetings WHERE [date] > 15/09/2004 15:03:06 AND [date] < 15/11/2004 15:03:06;


    .. and got the following error:



    Code:
     Microsoft OLE DB Provider for SQL Server error '80040e14' Line 1: Incorrect syntax near '15'.


    WHAT IS GOING ON ??!

    the column [date] is formatted as datetime

    I'm using Microsoft SQL Server v8.

    If anyone has any ideas, I would be really grateful for some help. This thing has been driving me mad!!
    Last edited by willmoss; Oct 15, 2004 at 07:09. Reason: changed title of thread

  2. #2
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,458
    Mentioned
    34 Post(s)
    Tagged
    1 Thread(s)
    suggest you enter your date strings in yyyy-mm-dd format

    e.g. WHERE [date] > '2004-09-15 15:00:07' AND [date] < '2004-11-15 15:00:07';
    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
  •