Solved Function to calculate your start and end dates for the current day (1 Viewer)

victorlindh

New member
Local time
Today, 18:37
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

  • Students.zip
    27.6 KB · Views: 20

victorlindh

New member
Local time
Today, 18:37
Joined
Mar 23, 2022
Messages
20
How do I apply this code?
Code:
StartDate: GetCurrentDayDates()(0)
EndDate: GetCurrentDayDates()(1)
 

bob fitz

AWF VIP
Local time
Today, 16:37
Joined
May 23, 2011
Messages
4,727
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.
 

victorlindh

New member
Local time
Today, 18:37
Joined
Mar 23, 2022
Messages
20
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.
 

GPGeorge

George Hepworth
Local time
Today, 08:37
Joined
Nov 25, 2004
Messages
1,919
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.
 

bob fitz

AWF VIP
Local time
Today, 16:37
Joined
May 23, 2011
Messages
4,727
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]))
 

victorlindh

New member
Local time
Today, 18:37
Joined
Mar 23, 2022
Messages
20
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]))
Thanks. Works perfectly
 

victorlindh

New member
Local time
Today, 18:37
Joined
Mar 23, 2022
Messages
20
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]))
 

bob fitz

AWF VIP
Local time
Today, 16:37
Joined
May 23, 2011
Messages
4,727
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?
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:37
Joined
Sep 21, 2011
Messages
14,364
Why not just Date instead of DateValue(Now()) :unsure:
 

victorlindh

New member
Local time
Today, 18:37
Joined
Mar 23, 2022
Messages
20
Code:
SELECT
   *,
   Now() >= StartDate And Now() < EndDate AS Active
FROM YourTable
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:37
Joined
Sep 21, 2011
Messages
14,364
I hope there is no time element in your fields?
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:37
Joined
Sep 21, 2011
Messages
14,364
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

Top Bottom