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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to find a Date from within a Range using Access?

How to find a Date from within a Range using Access?

Scheduled Pinned Locked Moved Database
databasehelptutorialquestion
8 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.
  • S Offline
    S Offline
    Squire Dude
    wrote on last edited by
    #1

    Hi, I have a bit of a problem with a Forms App using Access for the DB. I have a Calendar Control that has date ranges bolded from records in a table in the DB. I have the Calendar Control populated and now the user can select a date and find the event associated to the date. The date may be the "StartDate", "EndDate", or a date within the range of the "StartDate" & "EndDate" in a row. What I need help with is wrighting the SQL to bring back the record ID where the selected date falls between the StartDate & End Date and return the Record ID value. SELECT E_ID FROM Events WHERE "SelectedDate" is Between StartDate AND EndDate OR something like that???

    D 1 Reply Last reply
    0
    • S Squire Dude

      Hi, I have a bit of a problem with a Forms App using Access for the DB. I have a Calendar Control that has date ranges bolded from records in a table in the DB. I have the Calendar Control populated and now the user can select a date and find the event associated to the date. The date may be the "StartDate", "EndDate", or a date within the range of the "StartDate" & "EndDate" in a row. What I need help with is wrighting the SQL to bring back the record ID where the selected date falls between the StartDate & End Date and return the Record ID value. SELECT E_ID FROM Events WHERE "SelectedDate" is Between StartDate AND EndDate OR something like that???

      D Offline
      D Offline
      Dr Walt Fair PE
      wrote on last edited by
      #2

      Try SELECT E_ID FROM Events WHERE (SelectedDate >= StartDate) AND (SelectedDate <= EndDate) Make sure you replace all the date variables with their string representations for the SQL, of course.

      CQ de W5ALT

      Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

      S 1 Reply Last reply
      0
      • D Dr Walt Fair PE

        Try SELECT E_ID FROM Events WHERE (SelectedDate >= StartDate) AND (SelectedDate <= EndDate) Make sure you replace all the date variables with their string representations for the SQL, of course.

        CQ de W5ALT

        Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

        S Offline
        S Offline
        Squire Dude
        wrote on last edited by
        #3

        Hi Walt, Thanks for the sample code... It works great. But I have another issue that maybe you can help me with. The Value I am passing is a string with the DateTimeValue in it. I have put single quotes around the value and it works when I run the SQL manually... but when I run it in the app it rejectes it because the "Time" is still attached. My issue is how can I convert the string value to a Date ONLY value? I have tried Convert.ToDateTime(Value)... but that still has a Time in it. I tried DateTime.ParseExact(Value,... ,...) but I couldn't find a Date only filter. I am using this in a Forms App in C# on an Access DB, I build my SQL in the App and pass it over. Got any suggestions on how to convert the string value of "DateTime" to a "Date" only value? Thanks

        D 1 Reply Last reply
        0
        • S Squire Dude

          Hi Walt, Thanks for the sample code... It works great. But I have another issue that maybe you can help me with. The Value I am passing is a string with the DateTimeValue in it. I have put single quotes around the value and it works when I run the SQL manually... but when I run it in the app it rejectes it because the "Time" is still attached. My issue is how can I convert the string value to a Date ONLY value? I have tried Convert.ToDateTime(Value)... but that still has a Time in it. I tried DateTime.ParseExact(Value,... ,...) but I couldn't find a Date only filter. I am using this in a Forms App in C# on an Access DB, I build my SQL in the App and pass it over. Got any suggestions on how to convert the string value of "DateTime" to a "Date" only value? Thanks

          D Offline
          D Offline
          Dr Walt Fair PE
          wrote on last edited by
          #4

          Have your tried DateTime.ToShortDateString? A good summary of the assorted DateTime stuff is at [^]. I keep that page bookmarked.

          CQ de W5ALT

          Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

          S L 2 Replies Last reply
          0
          • D Dr Walt Fair PE

            Have your tried DateTime.ToShortDateString? A good summary of the assorted DateTime stuff is at [^]. I keep that page bookmarked.

            CQ de W5ALT

            Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

            S Offline
            S Offline
            Squire Dude
            wrote on last edited by
            #5

            Walt, Thanks for the pointer the page dose have a lot of great formats etc on it. I have added it to my favorites. I had to change the Single Quotes to # around each of the parameter dates and it worked great. Thanks for all the help and pointers. SquireDude

            1 Reply Last reply
            0
            • D Dr Walt Fair PE

              Have your tried DateTime.ToShortDateString? A good summary of the assorted DateTime stuff is at [^]. I keep that page bookmarked.

              CQ de W5ALT

              Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Walt Fair, Jr. wrote:

              DateTime.ToShortDateString

              Not ideal, as it depends on regional settings (and could contain all kinds of nonsense), whereas the database content does not. An explicit format would be the preferred one here. Here is an alternative summary[^]. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              Prolific encyclopedia fixture proof-reader browser patron addict?
              We all depend on the beast below.


              D 1 Reply Last reply
              0
              • L Luc Pattyn

                Walt Fair, Jr. wrote:

                DateTime.ToShortDateString

                Not ideal, as it depends on regional settings (and could contain all kinds of nonsense), whereas the database content does not. An explicit format would be the preferred one here. Here is an alternative summary[^]. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                Prolific encyclopedia fixture proof-reader browser patron addict?
                We all depend on the beast below.


                D Offline
                D Offline
                Dr Walt Fair PE
                wrote on last edited by
                #7

                True! Thanks for pointing that out, Luc.

                CQ de W5ALT

                Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

                L 1 Reply Last reply
                0
                • D Dr Walt Fair PE

                  True! Thanks for pointing that out, Luc.

                  CQ de W5ALT

                  Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  No problem. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  Prolific encyclopedia fixture proof-reader browser patron addict?
                  We all depend on the beast below.


                  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