473,396 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Date() Function is Date Time?

124 100+
I thought that the Date() function did not have a time component and that if you say <Date() as a criteria, it will only include records before today's date. What I'm trying to do is pull a field value for the most recent date (less than today's date) from a table with multiple dates. If I try
Expand|Select|Wrap|Line Numbers
  1. SELECT Max(tblUserCount.CurrentDate) AS MaxOfCurrentDate
  2. FROM tblUserCount
  3. HAVING (((Max(tblUserCount.CurrentDate))<Date())); 
There are no results even though there are records in tblUserCount with yesterday's date. Please advise.
Sep 3 '15 #1

✓ answered by Rabbit

That's because you're using the HAVING clause which is a filter that takes place after the aggregates are calculated. So it first takes the max date from all the records, then checks to see if the max date of all the records are before today's date. Which will never be true if you have any records with today's date.

5 1026
Rabbit
12,516 Expert Mod 8TB
That's because you're using the HAVING clause which is a filter that takes place after the aggregates are calculated. So it first takes the max date from all the records, then checks to see if the max date of all the records are before today's date. Which will never be true if you have any records with today's date.
Sep 3 '15 #2
BikeToWork
124 100+
Thanks, Rabbit. That makes sense, however I cannot use an aggregate function in a where clause, so is there some workaround? I'm just trying to find the maximum date in the data that is less than today. That may be yesterday or it may be a few days ago. Any advice. Thanks for your help.
Sep 4 '15 #3
Rabbit
12,516 Expert Mod 8TB
You don't need an aggregate in the where clause, there's no need to take the max for your filter.
Sep 4 '15 #4
BikeToWork
124 100+
I think I need two queries then, one for the Date() value and another for the max date less than the Date() value in the first query. Thank again for your help.
Sep 4 '15 #5
Rabbit
12,516 Expert Mod 8TB
You only need one query.

Expand|Select|Wrap|Line Numbers
  1. SELECT Max(tblUserCount.CurrentDate) AS MaxOfCurrentDate
  2. FROM tblUserCount
  3. WHERE tblUserCount.CurrentDate<Date(); 
Sep 4 '15 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Funnyweb | last post by:
I have just notices that the date() function is not returning the correct date/time on my "server". I am running apache2 on my winxp pro laptop. My system clock is set to the correct date,...
8
by: Dennis M. Marks | last post by:
What is the maximum valid date range for the date(yyyy,mm,dd) function. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/ Replace domain.invalid with dcsi.net -----= Posted via...
4
by: William Bradley | last post by:
I have two cells on a form. One of them is the "Production Date" and the other is the "Expiry Date". The "Expiry Date" is 183 days after the "Production Date." On an Excel spreadsheet, the...
4
by: Miguel Dias Moura | last post by:
Hello, i am just finishing a web site in ASP.net / VB using Dreamweaver MX 2004 and in all the pages i use the date/time format as follows: Date: DD-MM-YYYY Time: HH-MM (24 hours) Anyway,...
10
by: John Morgan | last post by:
Does anyone know what parameter should be used instead of Date = 0 for the optional parameter in the following function? Public Function dhAge(ByVal dtmBD As Date, Optional ByVal dtmDate As Date...
10
by: WebCM | last post by:
There is a function: http://paste.ubuntu.com/21865 It needs GMT date in YYYY-MM-DD HH:MM:SS format - in SQL: datetime. If date is the same as today, the function returns "Today". There is one...
4
by: Matt.Russett | last post by:
Hello, Here is what I am trying to do. I am running a report that brings back Requested Pick-Up Times and Actual Pick-Up Times. What I want to measure is the amount of times the Requested...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
3
by: murch.alexander | last post by:
I made a simple public function to set and return a date value (see below). I have a number of queries that call up the function to get the "As Of Date," which is typically set to today's date....
4
by: =?Utf-8?B?ZGNoMw==?= | last post by:
Is there a way to conditionally format a dateTime field to produce on result if the value is 10/31/2008 12:00 AM (user didn't enter a time) and another result if the value is 10/31/2008 5:30 PM...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.