![]() |
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. |
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. |
I do need the day to be one previous, but it depends on the time of day. If the entry is made between 12:00 AM and 5:00 PM, it needs to be the previous days date, if not the current day would be used.
|
Do you still need help on this?
|
Yes, sorry about the delay
|
Quote:
|
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. |
All times are GMT -8. The time now is 04:44 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project