Criteria in query to obtaining Date of fixed form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ElTipo
    New Member
    • Jul 2007
    • 36

    Criteria in query to obtaining Date of fixed form

    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
  • JConsulting
    Recognized Expert Contributor
    • Apr 2007
    • 603

    #2
    Originally posted by ElTipo
    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?

    Comment

    • Scott Price
      Recognized Expert Top Contributor
      • Jul 2007
      • 1384

      #3
      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.

      [CODE=vb]Public Function MyTuesday() As String

      Dim MyDate As Date
      Dim MyDate1 As Date
      Dim i As Integer

      MyDate = Date - 8

      'loop thru 7 days of week to find week ago Tuesday
      For i = 0 To 6
      'datepart for weekday, 1=sun, 7=sat
      If DatePart("w", MyDate - i) = 3 Then
      MyDate1 = MyDate - i
      Exit For
      End If
      Next

      MyTuesday = MyDate1
      'Debug.Print MyTuesday
      End Function

      Public Function MyMonday() As String
      Dim MyDate As Date
      Dim MyDate1 As Date
      Dim i As Integer

      MyDate = Date
      'loop through 7 days of week to find previous Monday
      For i = 0 To 6
      'datepart for weekday, 1=sun, 7=sat
      If DatePart("w", MyDate - i) = 2 Then
      MyDate1 = MyDate - i
      Exit For
      End If
      Next

      MyMonday = MyDate1
      'Debug.Print MyMonday
      End Function[/CODE]

      Then the query will look like this: [CODE=sql]SELECT tblEvent.EventI D, tblEvent.EventD ate
      FROM tblEvent
      WHERE (((tblEvent.Eve ntDate) BETWEEN MyTuesday() AND MyMonday()));
      [/CODE]

      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

      Comment

      • ElTipo
        New Member
        • Jul 2007
        • 36

        #4
        Originally posted by Scott Price
        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.

        [CODE=vb]Public Function MyTuesday() As String

        Dim MyDate As Date
        Dim MyDate1 As Date
        Dim i As Integer

        MyDate = Date - 8

        'loop thru 7 days of week to find week ago Tuesday
        For i = 0 To 6
        'datepart for weekday, 1=sun, 7=sat
        If DatePart("w", MyDate - i) = 3 Then
        MyDate1 = MyDate - i
        Exit For
        End If
        Next

        MyTuesday = MyDate1
        'Debug.Print MyTuesday
        End Function

        Public Function MyMonday() As String
        Dim MyDate As Date
        Dim MyDate1 As Date
        Dim i As Integer

        MyDate = Date
        'loop through 7 days of week to find previous Monday
        For i = 0 To 6
        'datepart for weekday, 1=sun, 7=sat
        If DatePart("w", MyDate - i) = 2 Then
        MyDate1 = MyDate - i
        Exit For
        End If
        Next

        MyMonday = MyDate1
        'Debug.Print MyMonday
        End Function[/CODE]

        Then the query will look like this: [CODE=sql]SELECT tblEvent.EventI D, tblEvent.EventD ate
        FROM tblEvent
        WHERE (((tblEvent.Eve ntDate) BETWEEN MyTuesday() AND MyMonday()));
        [/CODE]

        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

        Comment

        • Scott Price
          Recognized Expert Top Contributor
          • Jul 2007
          • 1384

          #5
          Glad you got it figured out!

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

          Regards,
          Scott from Perú

          Comment

          Working...