Insert System Date into query automatically


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Insert System Date into query automatically

  1. #1
    Join Date
    Jul 2009
    Posts
    1

    Insert System Date into query automatically

    I have an access query that I want to automatically insert the system date into for Start Date and End Date so it will query automatically query only for records that were entered today.

    I am currently prompting the user to enter the date manually e.g. Enter Start Date and Enter End Date with the following criteria;

    Between [Enter Start Date] And [Enter End Date]

    Can this be done?

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Use
    Code:
    Format(Now, "mm/dd/yyyy")
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    Now() includes date and time, so Format(Now, "mm/dd/yyyy") strips off the time part; but you could just use Date() which only returns the date, no time part.
    In your query, you are using Between, but if you are only looking for one day then you don't need Between which requires both a start and end value. Just change the criteria to Date()

  4. #4
    Join Date
    Oct 2008
    Posts
    142

    Dateadd might be what you are looking for

    To be short, I just thought:

    where date_field_in_table between date() and dateadd("d", 1, date())

    just maybe, it could be:

    where date_column_in_table between Format(Now, "mm/dd/yyyy") and dateadd("d", 1, Format(Now, "mm/dd/yyyy"))

    one of this two might work.

    if you want between right now and the next 24 hours

    where date_column_in_table between now and dateadd("h", 24, now)

    this last one should be a pretty good approximation.

    Best regards,

    Tonci Korsano

Similar Threads

  1. Query a date from database
    By matrik02 in forum VB Classic
    Replies: 0
    Last Post: 05-11-2007, 12:33 AM
  2. Replies: 4
    Last Post: 01-05-2007, 11:50 PM
  3. Replies: 4
    Last Post: 07-30-2006, 10:50 PM
  4. UNABLE TO INSERT DATE INTO SQL SERVER.
    By HEADACHE in forum Database
    Replies: 2
    Last Post: 10-25-2001, 03:46 AM
  5. Multi-row calculations
    By Bob Hines in forum Database
    Replies: 7
    Last Post: 04-27-2000, 11:14 AM

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