Professional Web Applications Themes

Querying a date closest to today - Coldfusion Database Access

How can i write a query that looks for the date that is closest to today, and only returns one record? I dont want to do a date range because the date may be in the past or future, and it may be the previous day, or 20 days out... Thanks, Andrew Calvo...

  1. #1

    Default Querying a date closest to today

    How can i write a query that looks for the date that is closest to today, and
    only returns one record? I dont want to do a date range because the date may be
    in the past or future, and it may be the previous day, or 20 days out...
    Thanks, Andrew Calvo

    Explorer5 Guest

  2. #2

    Default Re: Querying a date closest to today

    If you use MS SQL version 7 or later, you can try
    SELECT TOP(1) FROM table WHERE datecolume < getdate()
    mcsenow Guest

  3. #3

    Default Re: Querying a date closest to today

    You can use:

    SELECT TOP 1 MIN(ABS(DATEDIFF(mi, SOMEDATE, GETDATE())))

    then Order by
    MIN(ABS(DATEDIFF(mi, SOMEDATE, GETDATE())))

    OldCFer Guest

Similar Threads

  1. Help with Today's Date Display
    By kdennis4 in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: April 9th, 08:33 PM
  2. Prepopulate DateField with Today's Date
    By kdennis4 in forum Macromedia Flex General Discussion
    Replies: 5
    Last Post: April 8th, 07:10 PM
  3. Finding a date closest to a specific date
    By Explorer5 in forum Coldfusion Database Access
    Replies: 2
    Last Post: June 15th, 02:03 PM
  4. Filtering by today's date
    By benkayuk in forum Macromedia ColdFusion
    Replies: 2
    Last Post: April 5th, 01:38 PM
  5. compare a date in db field to today
    By Darren Heinrich in forum ASP Database
    Replies: 8
    Last Post: February 8th, 06:32 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