Solved Function to calculate your start and end dates for the current day

victorlindh

New member
Local time
Today, 06:08
Joined
Mar 23, 2022
Messages
20
How do I call this function to calculate your start and end dates for the current day. Kindly look at the attached database
 

Attachments

How do I apply this code?
Code:
StartDate: GetCurrentDayDates()(0)
EndDate: GetCurrentDayDates()(1)
 
How do I apply this code?
Code:
StartDate: GetCurrentDayDates()(0)
EndDate: GetCurrentDayDates()(1)
Where do you want to use it?
In a query, you could use each line as an expression to create a calculated field for each value.
On a form, you could use:
Code:
= GetCurrentDayDates()(0)
and
Code:
= GetCurrentDayDates()(1)
as the Control Source properties of two unbound textboxes.
 
Where do you want to use it?
In a query, you could use each line as an expression to create a calculated field for each value.
On a form, you could use:
Code:
= GetCurrentDayDates()(0)
and
Code:
= GetCurrentDayDates()(1)
as the Control Source properties of two unbound textboxes.
I want to use in a query. Apparently it is not working. Thanks in advance.
 
I want to use in a query. Apparently it is not working. Thanks in advance.
What does "it is not working" mean? Errors? Wrong results? Nothing?

Show us, please, the VBA in the function called GetCurrentDayDates() as well.
 
I want to use in a query. Apparently it is not working. Thanks in advance.
In that case, I would use the following expressions as calculated fields in the query:

startOfDay: DateValue(Now())
endOfDay: DateAdd("s",-1,DateAdd("d",1,[startOfDay]))
 
Good. Always glad to help if I can ;)
Thanks. I have encountered a slight problem. I am trying to filter using your expressions
Code:
WHERE >=DateValue(Now()) AND <=DateAdd("s",-1,DateAdd("d",1,[StartOfDay]))
 
Thanks. I have encountered a slight problem. I am trying to filter using your expressions
Code:
WHERE >=DateValue(Now()) AND <=DateAdd("s",-1,DateAdd("d",1,[StartOfDay]))
In plain words, can you explain what criteria you want to apply?
 
Why not just Date instead of DateValue(Now()) :unsure:
 
Code:
SELECT
   *,
   Now() >= StartDate And Now() < EndDate AS Active
FROM YourTable
 
I hope there is no time element in your fields?
 
I will appreciate if you added input on time element.
Depends on the values of those date fields.

Now() is 27/04/2024 12:12:20
If Endate is 27/04/2024 10:12:20 that is not going to work.
Best to use Datvalue() on those fields to be sure.

Be better to use Date() as that would be 27/04/2024 00:00:00 and so would less that EndDate, but then not > StartDate if that has time element.
Code:
Date() >= DateValue(StartDate) And Date() <= DateValue(EndDate) AS Active
 

Users who are viewing this thread

Back
Top Bottom