473,394 Members | 1,889 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,394 software developers and data experts.

Criteria in query to obtaining Date of fixed form

36
Hello People,

As I can obtain data with a dated fixed criteria. Without utilizing a parameter.

Example:

My field is [DateReceived].

I need a criteria that indicate me a range date on Tuesday of the previous week to Monday of the current week.

<Spanish Ver>
Hola amigos,

Como puedo obtener datos con un criterio de fecha fijo. Sin utilizar un parametro.

Ejemplo:

Mi campo es [DateReceived].

Necesito saber que criterio utilizar para extraer datos desde el martes de la semana anterior hasta el lunes de la semana actual.

Thanks, Gracias! for any answer
Sep 6 '07 #1
4 2277
JConsulting
603 Expert 512MB
Hello People,

As I can obtain data with a dated fixed criteria. Without utilizing a parameter.

Example:

My field is [DateReceived].

I need a criteria that indicate me a range date on Tuesday of the previous week to Monday of the current week.

<Spanish Ver>
Hola amigos,

Como puedo obtener datos con un criterio de fecha fijo. Sin utilizar un parametro.

Ejemplo:

Mi campo es [DateReceived].

Necesito saber que criterio utilizar para extraer datos desde el martes de la semana anterior hasta el lunes de la semana actual.

Thanks, Gracias! for any answer
ola,
How do you want that range returned? how are you using it? the coding isn't hard, but how then would your field fit into it? do you want all 7 dates put into that field?
Sep 7 '07 #2
Scott Price
1,384 Expert 1GB
Hola, El Tipo,

¿Como está? No hemos visto a ud por un tiempito :-)

This will be a WHERE criteria used in a query to return data BETWEEN Tuesday a week ago AND last Monday.

This code goes into a public module in the VBA editor window.

Expand|Select|Wrap|Line Numbers
  1. Public Function MyTuesday() As String
  2.  
  3. Dim MyDate As Date
  4. Dim MyDate1 As Date
  5. Dim i As Integer
  6.  
  7. MyDate = Date - 8
  8.  
  9. 'loop thru 7 days of week to find week ago Tuesday
  10. For i = 0 To 6
  11. 'datepart for weekday, 1=sun, 7=sat
  12. If DatePart("w", MyDate - i) = 3 Then
  13. MyDate1 = MyDate - i
  14. Exit For
  15. End If
  16. Next
  17.  
  18. MyTuesday = MyDate1
  19. 'Debug.Print MyTuesday
  20. End Function
  21.  
  22. Public Function MyMonday() As String
  23. Dim MyDate As Date
  24. Dim MyDate1 As Date
  25. Dim i As Integer
  26.  
  27. MyDate = Date
  28. 'loop through 7 days of week to find previous Monday
  29. For i = 0 To 6
  30. 'datepart for weekday, 1=sun, 7=sat
  31. If DatePart("w", MyDate - i) = 2 Then
  32. MyDate1 = MyDate - i
  33. Exit For
  34. End If
  35. Next
  36.  
  37. MyMonday = MyDate1
  38. 'Debug.Print MyMonday
  39. End Function
Then the query will look like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblEvent.EventID, tblEvent.EventDate
  2. FROM tblEvent
  3. WHERE (((tblEvent.EventDate) BETWEEN MyTuesday() AND MyMonday()));
  4.  
You'll change the names of the tables and fields to reflect your tables and fields.

If you need this explained in Spanish, I'll give it a try! :-)

Regards,
Scott
Sep 7 '07 #3
ElTipo
36
Hola, El Tipo,

¿Como está? No hemos visto a ud por un tiempito :-)

This will be a WHERE criteria used in a query to return data BETWEEN Tuesday a week ago AND last Monday.

This code goes into a public module in the VBA editor window.

Expand|Select|Wrap|Line Numbers
  1. Public Function MyTuesday() As String
  2.  
  3. Dim MyDate As Date
  4. Dim MyDate1 As Date
  5. Dim i As Integer
  6.  
  7. MyDate = Date - 8
  8.  
  9. 'loop thru 7 days of week to find week ago Tuesday
  10. For i = 0 To 6
  11. 'datepart for weekday, 1=sun, 7=sat
  12. If DatePart("w", MyDate - i) = 3 Then
  13. MyDate1 = MyDate - i
  14. Exit For
  15. End If
  16. Next
  17.  
  18. MyTuesday = MyDate1
  19. 'Debug.Print MyTuesday
  20. End Function
  21.  
  22. Public Function MyMonday() As String
  23. Dim MyDate As Date
  24. Dim MyDate1 As Date
  25. Dim i As Integer
  26.  
  27. MyDate = Date
  28. 'loop through 7 days of week to find previous Monday
  29. For i = 0 To 6
  30. 'datepart for weekday, 1=sun, 7=sat
  31. If DatePart("w", MyDate - i) = 2 Then
  32. MyDate1 = MyDate - i
  33. Exit For
  34. End If
  35. Next
  36.  
  37. MyMonday = MyDate1
  38. 'Debug.Print MyMonday
  39. End Function
Then the query will look like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblEvent.EventID, tblEvent.EventDate
  2. FROM tblEvent
  3. WHERE (((tblEvent.EventDate) BETWEEN MyTuesday() AND MyMonday()));
  4.  
You'll change the names of the tables and fields to reflect your tables and fields.

If you need this explained in Spanish, I'll give it a try! :-)

Regards,
Scott
Hola my gente, Hi my people. Thanks for the answer and excuses for my late.

Ok, I put in my query this criteria:

Between Date() - WeekDay(Date(), 0) - 4 And Date() - WeekDay(Date(), 0) + 3

I think it's work!

Date() - WeekDay(Date(), 0) - 4 = Actual Weekday - 4 send to tuesday for previous weekday

Date() - WeekDay(Date(), 0) + 3 = Actual Weekday +3 send to actual tuesday not previous

Thanks A lot Scott.... from Puerto Rico Gracias
Sep 9 '07 #4
Scott Price
1,384 Expert 1GB
Glad you got it figured out!

¡Qué bueno que llegó a una solución!

Regards,
Scott from Perú
Sep 9 '07 #5

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

Similar topics

11
by: David B | last post by:
I have 2 querys with the following in the date criteria Between DateAdd("m",-6,(!!)) And (!!) Between DateAdd("m",-24,(!!)) And DateAdd("m",-6,(!!)) Problem is they both look at the same...
1
by: Matthew | last post by:
I have a form with fields that act as user specified criteria for a form. Two of the fields are start and finish date. The fields in my query are "ID", "TimeStart", "TimeEnd", etc. Currently, I...
2
by: Matthew | last post by:
Hey , I have built a query which takes values from unbounded fields on a form, and it all works except for one thing. I have a few fields in my query that are dates. I also have a start and...
2
by: dskillingstad | last post by:
I'm trying to set up a parameter query based on an unbound form. This search form has about 5 text boxes where the user can type in values within each box and search a specific table based on the...
4
by: meganrobertson22 | last post by:
Hi Everyone- I have a question about how to add and then use the "All" selection in a combo box. I am trying to figure out how to: (1) add "All" as a selection to a combo box and then (2)...
4
by: EJO | last post by:
In the query builder, I can create a query that will take a date/time as criteria, and the query finds the records: SELECT SRSrvcsEquip.Stock, SRSrvcsEquip.Activity, SRSrvcsEquip.EquipOwned,...
2
by: Mark Roughton | last post by:
I have a form where the users need to view records for various criteria, one of which is a date field on which they may wish to view all related data for the selected date, for all dates upto and...
8
by: Dr Al | last post by:
I have a table with four date fields, some of which may not be filled in based on our data entry needs. I have a criteria set as <date()-180 which is supposed to pull dates older than 180 days ago....
17
by: sharsy | last post by:
Hello guys, I would like some help in generating query criteria that will identify credit cards that have expired on an access database. The specific Field is formatted with a Data Type of...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.