Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date determination within a time period.

Status
Not open for further replies.

Brawn

Programmer
Jul 5, 2001
73
0
0
CA
I'm developing an application that needs to be able to tell if a date is within the
- last day
- last week
- last 2-weeks
- last month

any functions or algorithms that might help me would be much appreciated.

Other considerations are:
-leap years.
-format of dates.

[neutral] Brawn

"My mind is my Shrine,
and my body the Temple around it."

-The difference between genius and stupidity is that genius has its limits-
 
The DateAdd function may be useful for these.

dim Today as Date
dim CheckDate as Date

Today = Now()
CheckDate = DateAdd("d", -1, Today)
If ((YourDate >= CheckDate) and (YourDate <= Today)) then
<date is within the last day>
End If

CheckDate = DateAdd(&quot;ww&quot;, -2, Today)
If ((YourDate >= CheckDate) and (YourDate <= Today)) then
<date is within the last 2 weeks>
End If

the first parameter is the interval, and can be any of the following items
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Awesome,

Thanks. Brawn

&quot;My mind is my Shrine,
and my body the Temple around it.&quot;

-The difference between genius and stupidity is that genius has its limits-
 
Alternate offer,

Code:
Public Function basHowManyDays(Optional DtToChk As Date) As String

    'Michael Red    5/10/2002   How Far back is the date?

    Dim Interval As Long
    Dim DaysInMnth As Integer

    If (IsMissing(DtToChk)) Then
        DtToChk = Date
    End If

    Interval = DateDiff(&quot;d&quot;, DtToChk, Date)

    DaysInMnth = Day(DateSerial(Year(DtToChk), Month(DtToChk) + 1, 0))

    Select Case Interval

        Case Is <= 1
            basHowManyDays = &quot;Last Day&quot;

        Case 2 To 7
            basHowManyDays = &quot;Last Week&quot;

        Case 8 To 14
            basHowManyDays = &quot;Last Two Weeks&quot;

        Case 15 To DaysInMnth
            basHowManyDays = &quot;Last Month&quot;

        Case Else
            basHowManyDays = &quot;More than a Month&quot;
    End Select

End Function
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top