![]() |
![]() |
#1 (permalink) |
Upright
|
Access Help
I working on a program that will take into account the time of day before determining the date. I know it will take an If, Then statement (I think), but all I can think of is
If [Time] between 12:00:00 AM and 05:00:00 PM then [Date] = Date()-1 Hopefully that will make sense somehow. That code does not work obviously, I just don't know what to do. Any help would be appreciated. |
![]() |
![]() |
#2 (permalink) |
Stop. Think. Question.
Location: Redondo Beach, CA
|
What are you trying to accomplish?
You can call the function Date() - 1 and it will subtract one day from the current day. Likewise, Date() - 30 is 30 days earlier than the current date.
__________________
How you do anything is how you do everything. |
![]() |
![]() |
#7 (permalink) |
Stop. Think. Question.
Location: Redondo Beach, CA
|
Try this:
Private Sub DateSub() ' declare variables Dim intHourCurrent As Integer Dim blnHourValid As Boolean Dim strYourDate As String ' fetch current hour intHourCurrent = DatePart("h", Now) ' if hour is between 00:00 and 17:00 then set flag to true, else false blnHourValid = IIf((intHourCurrent >= 0 And intHourCurrent <= 17), True, False) ' if flag is true, store the previous day's date, else the current date strYourDate = IIf(blnHourValid, Date - 1, Date) ' display results MsgBox ("blnHourValid = " & blnHourValid & ", strYourDate = " & strYourDate) End Sub EDIT: I used the current time on my PC clock which was 8:30 am. I didn't change the clock to test the FALSE condition.
__________________
How you do anything is how you do everything. Last edited by rubicon; 06-10-2003 at 07:35 AM.. |
![]() |
Tags |
access |
|
|