Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL query for date

SQL query for date

Scheduled Pinned Locked Moved Database
databasehelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Johnkokk
    wrote on last edited by
    #1

    I have a field in an access database called day and is declared as DATE/TIME I want to find through SQL all records with dates between 01/03/2010 and 15/03/2010 When i sent the sql command 'Select * from journal1 where day between 01/03/2010 and 15/03/2010' it does not work. Even if i try 'Select * from journal1 where date(day) between 01/03/2010 and 15/03/2010' it doesn't work. I am almost sure that the problem is because the day includes also a time portion in it, but if i put date(day) shouldn't this be working ? Thanks.

    L 1 Reply Last reply
    0
    • J Johnkokk

      I have a field in an access database called day and is declared as DATE/TIME I want to find through SQL all records with dates between 01/03/2010 and 15/03/2010 When i sent the sql command 'Select * from journal1 where day between 01/03/2010 and 15/03/2010' it does not work. Even if i try 'Select * from journal1 where date(day) between 01/03/2010 and 15/03/2010' it doesn't work. I am almost sure that the problem is because the day includes also a time portion in it, but if i put date(day) shouldn't this be working ? Thanks.

      L Offline
      L Offline
      loyal ginger
      wrote on last edited by
      #2

      Use # to delimit date:

      Select * from journal1 where day between #01/03/2010# and #15/03/2010#

      However, I am not sure how to tell Access if it is mm/dd/yyyy or dd/mm/yyyy. If you can use a parameterized query command, this will be easier.

      C J 2 Replies Last reply
      0
      • L loyal ginger

        Use # to delimit date:

        Select * from journal1 where day between #01/03/2010# and #15/03/2010#

        However, I am not sure how to tell Access if it is mm/dd/yyyy or dd/mm/yyyy. If you can use a parameterized query command, this will be easier.

        C Offline
        C Offline
        Corporal Agarn
        wrote on last edited by
        #3

        If the column name is "day" you will most likely need brackets as in [day].

        1 Reply Last reply
        0
        • L loyal ginger

          Use # to delimit date:

          Select * from journal1 where day between #01/03/2010# and #15/03/2010#

          However, I am not sure how to tell Access if it is mm/dd/yyyy or dd/mm/yyyy. If you can use a parameterized query command, this will be easier.

          J Offline
          J Offline
          Johnkokk
          wrote on last edited by
          #4

          Well using # worked, but actually it expects the date to be completely reversed. So if i use 'select * from journal1 where day>#15/03/2010#' it doesn't get any results, but if i use 'select * from journal1 where day>#2010/03/15#' it is working. Is it possible to change this ? Thanks.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups