Access Round down not working 100%

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi All,

What im trying to do is round down to the nearest half half hour

so if createddatetime is say 03/07/2020 00:05:27 then the period should fall in 00:00:00
if its 00:31:00 then it should fall in 00:30:00
if its 01:01:00 then 01:00:00, if 01:59:57 then 01:30

Hope this makes sense as occasionally the formula below is catagorising into 00:05 and 00:25etc

This is my Formula in VBA

CreatedPeriod = FORMAT(CStr(ROUND(([CreatedDateTime] - INT([CreatedDateTime]))*48,0)/48), ""hh:nn"")
 
In the other thread it says this but this doesn’t always rounddown
TimeSerial(Hour([mytime]),(Minute([mytime])\30)*30,0)

my created date time has a date and time in there so my aim was to take the time from
That and put into a category by rounding down to nearest half hour

i thought it would be a lot simpler to do like in excel using the Floor Function

any help with my example would really be appreciated

thank you
You need to supply examples?, as it appeared to work for me.?
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I generated some data.
The query was
Code:
SELECT Transactions.ID, DateAdd("n",[ID],[TransactionDate]) AS Expr1, TimeSerial(Hour(DateAdd("n",[ID],[TransactionDate])),(Minute(DateAdd("n",[ID],[TransactionDate]))\30)*30,0) AS Expr2
FROM Transactions;

The results (well only enough to show it works)
1593962194131.png

1593962239603.png
 
Upvote 0
I generated some data.
The query was
Code:
SELECT Transactions.ID, DateAdd("n",[ID],[TransactionDate]) AS Expr1, TimeSerial(Hour(DateAdd("n",[ID],[TransactionDate])),(Minute(DateAdd("n",[ID],[TransactionDate]))\30)*30,0) AS Expr2
FROM Transactions;

The results (well only enough to show it works)
View attachment 17633
View attachment 17634

Here is my code trying to implement your code

CreatedDateTime is stored like this
22/06/2020 15:45:23 Etc

Format(TimeSerial(Hour([CreatedDateTime]), Minute([CreatedDateTime])\30)*30,0),””hh:nn””)

Is this correct?
 
Upvote 0
Here is my code trying to implement your code

CreatedDateTime is stored like this
22/06/2020 15:45:23 Etc

Format(TimeSerial(Hour([CreatedDateTime]), Minute([CreatedDateTime])\30)*30,0),””hh:nn””)

Is this correct?
Well have you tried it? as when I used the Format as well yesterday, that was the format that was displayed?
 
Upvote 0
Be aware, if you use Format() you will turn the time into a string.? I'd probably leave it as a time value and format when needed.?
Up to you.
 
Upvote 0
The main thing i wernt sure about was weather i needed to strip off the date element by using INT and also whether i needed to use rounddown outside the formula u provided
 
Upvote 0
The main thing i wernt sure about was weather i needed to strip off the date element by using INT and also whether i needed to use rounddown outside the formula u provided
You are already stripping off the date element as you are only using the hour minute and seconds?
The formula linked to provides the rounddown, so I am at a loss as to what is the issue?
 
Upvote 0
Sorry my bad - the syntax i put was wrong with the double quotesNot applied properly

i double double quoted it

thank you and ill give that a go
 
Upvote 0
Im getting this error message

Syntax error in update statement (I update the table once i import it in) in VBA

DoCmd.RunSQL "UPDATE tbl_Email_Rolling " & _
"SET ModifiedDate = INT([ModifiedDateTime]), " & _
"ModifiedPeriod = Format(TimeSerial(Hour([ModifiedDateTime]), Minute([ModifiedDateTime])\30)*30,0),""hh:nn"")"
 
Upvote 0
Put the sql into a string and debug.print that string. That will show you what is wrong.

From here it looks like should should be concatenating your rounded tme with the text.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top