round now()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a button that enters the current time in when a person clicks it.
When you select the "In" Button, the text box (linked to in on a table) is
set to the current time. It is very simple: [In]=now()

However, I would like it to enter the current time, but round 15 minutes.
How can this be done?
 
Dogpigfish,

Caution: air code (untested)...

Dim InputTime As Date
Dim CurrentSeconds As Integer
Dim RoundedSeconds As Integer
InputTime = Now
CurrentSeconds = Minute(InputTime) * 60 + Second(InputTime)
RoundedSeconds = CurrentSeconds Mod 900
If RoundedSeconds < 450 Then
Me![In] = DateAdd("s", RoundedSeconds * -1, InputTime)
Else
Me![In] = DateAdd("s", 900 - RoundedSeconds, InputTime)
End If
 
Worked perfectly, and I didn't even have to change any of the code. Thanks.

Steve Schapel said:
Dogpigfish,

Caution: air code (untested)...

Dim InputTime As Date
Dim CurrentSeconds As Integer
Dim RoundedSeconds As Integer
InputTime = Now
CurrentSeconds = Minute(InputTime) * 60 + Second(InputTime)
RoundedSeconds = CurrentSeconds Mod 900
If RoundedSeconds < 450 Then
Me![In] = DateAdd("s", RoundedSeconds * -1, InputTime)
Else
Me![In] = DateAdd("s", 900 - RoundedSeconds, InputTime)
End If

--
Steve Schapel, Microsoft Access MVP

I have a button that enters the current time in when a person clicks it.
When you select the "In" Button, the text box (linked to in on a table) is
set to the current time. It is very simple: [In]=now()

However, I would like it to enter the current time, but round 15 minutes.
How can this be done?
 
Back
Top