dbTalk Databases Forums  

Round Now() to Nearest Hour?

comp.database.ms-access comp.database.ms-access


Discuss Round Now() to Nearest Hour? in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
screenwriter776
 
Posts: n/a

Default Round Now() to Nearest Hour? - 04-19-2004 , 12:47 PM






Hi, folks -

I'm trying to default one of my table fields to Now(), rounded to the
nearest hour. If I enter a new record at 4/19 10:29 am, I'd like the
field to store 4/19 10:00 am. If I enter a record at 4/19 10:31 am,
I'd like the field to store 4/19 11:00 am, etc.

Can't seem to find any basic "round" functions to attach to now() and
achieve this result in the "default value" of my field.

Any advice would be VERY appreciated!

Thanks,

sw776

Reply With Quote
  #2  
Old   
Ray
 
Posts: n/a

Default Re: Round Now() to Nearest Hour? - 04-27-2004 , 05:12 AM






screenwriter776 (AT) hotmail (DOT) com (screenwriter776) wrote in message news:<2faa126e.0404190947.73f80fb2 (AT) posting (DOT) google.com>...
Quote:
Hi, folks -

I'm trying to default one of my table fields to Now(), rounded to the
nearest hour. If I enter a new record at 4/19 10:29 am, I'd like the
field to store 4/19 10:00 am. If I enter a record at 4/19 10:31 am,
I'd like the field to store 4/19 11:00 am, etc.

Can't seem to find any basic "round" functions to attach to now() and
achieve this result in the "default value" of my field.

Any advice would be VERY appreciated!

Thanks,

sw776

Hello SW776,

A question I have is, are you inputting your data from the datasheet
view of your table? If so, perhaps you should set up a form for
inputting. Just checking.

If you are using a form, one thing you can do is add another column
to the Record Source query like the following:

TimeRounded: rndTime([txtAutoDateField])

Add your date text field into the function above and
replace "txtAutoDateField".

This sources the following function located in a module.
----
Function rndTime(x As Variant) As Variant

Dim getRndTime As Date
Dim sMinutes As String, sHours As String

sMinutes = DatePart("n", x)
sHours = DatePart("h", x)

Select Case sMinutes
Case 0 To 29.59
rndTime = Format(x, "d" & "/" & "m" & " " & sHours & ":00:00")
Case 30 To 59
rndTime = Format(x, "d" & "/" & "m" & " " & sHours + 1 & ":00:00")
End Select

End Function
----

Perhaps you can name the module "mod01RoundTime".

Then, run the query. You can use the field according to your
needs. From the form, have the new formated date saved into
a field from an "After Update" property of a field that receives
data input for every record as an example.

Regards,

Ray


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.