Querying a date closest to today

Ask a Question related to Coldfusion Database Access, Design and Development.

  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. Similar Questions and Discussions

    1. Finding a date closest to a specific date
      I have a table which has a bunch of dates, from 2003, all the way until 2006. I'm trying to figure out an SQL statement which will allow me to find...
    2. SUPER-UX Cray - what is the closest popular unix version ?
      Hi, Which unix version is the closest to SUPER-UX ? Is HP-UX a good guess ? Unfortunately I can't afford to buy a Cray but would like to...
    3. Converting RGB colors to closest Pantone
      This sound like it should be obvious but I can't see how to do this. I'm working on graphics created for websites and the colors are all RGB. I...
    4. compare a date in db field to today
      Hi I have a date field in Access that I want to return if the date is less than 30 days old. i have built this query, but I'm not using the...
    5. [DVD burner] Which one to buy today?
      I am thinking about buying an external firewire DVD burner for my G4 iMac 700mhz, 512MB ram. Which one would be today the best one, e.g. the most...
  3. #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

  4. #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

Posting Permissions

  • You may not post new threads
  • You may 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