Computer Learning Zone CLZ Access Excel Word Windows

One of the basic rules of the universe is that nothing is perfect. Perfection simply doesn't exist. Without imperfection, neither you nor I would exist.

-Stephen Hawking
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Active Server Pages Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Date Function
Diane Stankevitz 
     
4 years ago
I am trying to filter my sql string to show only data that has been entered on the current date.

It works for a specific date:
SQL = "SELECT * FROM VisitorT WHERE VisitorStartDate='5/23/2022 12:53:12 PM' ORDER BY VisitorStartDate DESC "

But I want it for the current date. I keep getting an error when I write it like this:

SQL = "SELECT * FROM VisitorT WHERE VisitorStartDate= " & (Date()) & "ORDER BY VisitorStartDate DESC "

or a variety of other ways.

Can anyone help me with the correct line of code. :-)
Kevin Robertson  @Reply  
          
4 years ago
You are missing a space between the Date function and the Order By clause.

SQL = "SELECT * FROM VisitorT WHERE VisitorStartDate=#" & Date() & "# ORDER BY VisitorStartDate DESC "
Scott Axton  @Reply  
        
4 years ago
One other little subtle thing as well.

In SQL dates need to be surrounded by the # symbol so that Access knows to treat it as a date.  
Kevin included it in his response but didn't point it out.
Richard Rost  @Reply  
          
4 years ago
Remember the # are for Access. If this is ASP on SQL Server then you need:

SQL = "SELECT * FROM VisitorT WHERE VisitorStartDate='" & Date() & "' ORDER BY VisitorStartDate DESC"

Yeah, I know... it gets me sometimes too.
Richard Rost  @Reply  
          
4 years ago
And don't forget if the dates in your table have TIMES on them, then comparing to an exact date might not give you any records. :)
Scott Axton  @Reply  
        
4 years ago
OOPS-
I missed that this was in ASP TechHelp.  

Guess that's why you are the boss Richard.
Diane Stankevitz OP  @Reply  
     
4 years ago
Thank you everyone. That help!!!!!
Richard Rost  @Reply  
          
4 years ago
:)

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Active Server Pages Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 12:15:57 PM. PLT: 1s