Access Date/Time Field


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Access Date/Time Field

  1. #1
    Jeremiah Guest

    Access Date/Time Field


    Is there anything special one has to do to retrieve a date/time field from
    an Access database using ODBC? I have a chunk of code that runs a query on
    an Access database and then steps through the recordset outputting field
    values. When I try to retrieve the date/time field in a particle table I
    get an error. I've tried assigning the recordset value to a date/time variable
    and also a variant but both cases give me an error. I can open up Access
    and see that the value is in the database in a readable format. Any suggestions?
    Thanks in advance.

  2. #2
    mike Guest

    Re: Access Date/Time Field


    "Jeremiah" <sabjkb@speakeasy.org> wrote:
    >
    >Is there anything special one has to do to retrieve a date/time field from
    >an Access database using ODBC? I have a chunk of code that runs a query

    on
    >an Access database and then steps through the recordset outputting field
    >values. When I try to retrieve the date/time field in a particle table I
    >get an error. I've tried assigning the recordset value to a date/time variable
    >and also a variant but both cases give me an error. I can open up Access
    >and see that the value is in the database in a readable format. Any suggestions?
    >Thanks in advance.



    try putting # around the date feild when retreiving it.

    example sql = "SELECT * FROM table WHERE DATE = #" & datevariable & "#"

  3. #3
    Douglas J. Steele Guest

    Re: Access Date/Time Field

    "mike" <expos65@hotmail.com> wrote in message
    news:3aa63960$1@news.devx.com...
    >
    > "Jeremiah" <sabjkb@speakeasy.org> wrote:
    > >
    > >Is there anything special one has to do to retrieve a date/time field

    from
    > >an Access database using ODBC? I have a chunk of code that runs a query

    > on
    > >an Access database and then steps through the recordset outputting field
    > >values. When I try to retrieve the date/time field in a particle table I
    > >get an error. I've tried assigning the recordset value to a date/time

    variable
    > >and also a variant but both cases give me an error. I can open up Access
    > >and see that the value is in the database in a readable format. Any

    suggestions?
    > >Thanks in advance.

    >
    >
    > try putting # around the date feild when retreiving it.
    >
    > example sql = "SELECT * FROM table WHERE DATE = #" & datevariable & "#"


    And when you do that, it's critical that the date be in mm/dd/yyyy format.

    To ensure it is, try

    sql = "SELECT * FROM table WHERE DATE = " & Format$(datevariable,
    "\#mm\/dd\/yyyy\#")

    HTH

    --

    Doug Steele, Microsoft Access MVP
    Beer, Wine and Database Programming. What could be better?
    Visit "Doug Steele's Beer and Programming Emporium"
    http://I.Am/DougSteele/






Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center