Professional Web Applications Themes

date question - Microsoft SQL / MS SQL Server

I want to select all items that where recorded today for instance Todays Date = Now() in this case 8/18/2003 [Key] [int] [Date] [datetime] Key Date 1 2003-08-12 18:12:11.230 2 2003-08-12 13:43:15.530 3 2003-08-13 10:45:01.230 4 2003-08-18 13:26:26.520 5 2003-08-18 12:31:24.340 6 2003-08-18 10:23:21.360 Results should be 4 2003-08-18 13:26:26.520 5 2003-08-18 12:31:24.340 6 2003-08-18 10:23:21.360...

  1. #1

    Default date question

    I want to select all items that where recorded today for instance

    Todays Date = Now() in this case 8/18/2003

    [Key] [int]
    [Date] [datetime]

    Key Date
    1 2003-08-12 18:12:11.230
    2 2003-08-12 13:43:15.530
    3 2003-08-13 10:45:01.230
    4 2003-08-18 13:26:26.520
    5 2003-08-18 12:31:24.340
    6 2003-08-18 10:23:21.360

    Results should be

    4 2003-08-18 13:26:26.520
    5 2003-08-18 12:31:24.340
    6 2003-08-18 10:23:21.360






    DJP Guest

  2. #2

    Default Re: date question

    SELECT Key, [date]
    FROM myTable
    WHERE [Date] >= CONVERT(CHAR(8), GETDATE(), 112)
    AND [Date] < CONVERT(CHAR(8), DATEADD(dd, 1, GETDATE(), 112)

    --
    Jacco Schalkwijk MCDBA, MCSD, MCSE
    Database Administrator
    Eurostop Ltd.


    "DJP" <DJPN*O*S*P*A*M*.com> wrote in message
    news:uu60b.52437$tampabay.rr.com... 


    Jacco Guest

  3. #3

    Default Re: date question

    Well actually you should use one more convert to make them a datetime
    datatype instead of chars.


    --

    Andrew J. Kelly
    SQL Server MVP


    "Jacco Schalkwijk" <co.uk> wrote in message
    news:phx.gbl... 
    >
    >[/ref]


    Andrew Guest

  4. #4

    Default Re: date question

    Hi Andrew,

    There will be an implicit convert, but doing an explicit convert is indeed
    better coding practice.


    "Andrew J. Kelly" <com> wrote in message
    news:phx.gbl... 
    > >
    > >[/ref]
    >
    >[/ref]


    Jacco Guest

  5. #5

    Default Re: date question

    Thanks for you help


    "Jacco Schalkwijk" <co.uk> wrote in message
    news:phx.gbl... 
    > >
    > >[/ref]
    >
    >
    >[/ref]


    DJP Guest

Similar Threads

  1. DATE Question
    By Shaun in forum PHP Development
    Replies: 9
    Last Post: November 20th, 03:25 PM
  2. date() question
    By Yang Li Ke in forum PHP Development
    Replies: 3
    Last Post: October 23rd, 12:37 PM
  3. date formatting question
    By Bernhard Hörlberger in forum PHP Development
    Replies: 1
    Last Post: August 19th, 10:28 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139