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"")
 
cool will do that - are you saying i need to wrap the formula in cStr()?
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
No. To keep things simple I'd assign the format etc to a string and use that in your RunSQL.
Plus DO NOT keep changing my code :mad:
The Minute had a ( before it and you removed it? It took me ages to find out what worked no longer worked.:mad:

Whenever you are constructing SQL strings like this, debug.print them first until it is correct, then either remove or comment out.

Code:
Sub testSQL()
Dim strSQL As String
Dim strTime As String
Dim ModifiedDateTime As Date

ModifiedDateTime = Now()
strTime = Format(TimeSerial(Hour(ModifiedDateTime), (Minute(ModifiedDateTime) \ 30) * 30, 0), "hh:nn")
strSQL = "UPDATE tbl_Email_Rolling "
strSQL = strSQL & "SET ModifiedDate = DATEVALUE([ModifiedDateTime]), "
strSQL = strSQL & "ModifiedPeriod = '" & strTime & "'"

Debug.Print strSQL

DoCmd.RunSQL strSQL
End Sub
 
Upvote 0
No. To keep things simple I'd assign the format etc to a string and use that in your RunSQL.
Plus DO NOT keep changing my code :mad:
The Minute had a ( before it and you removed it? It took me ages to find out what worked no longer worked.:mad:

Whenever you are constructing SQL strings like this, debug.print them first until it is correct, then either remove or comment out.

Code:
Sub testSQL()
Dim strSQL As String
Dim strTime As String
Dim ModifiedDateTime As Date

ModifiedDateTime = Now()
strTime = Format(TimeSerial(Hour(ModifiedDateTime), (Minute(ModifiedDateTime) \ 30) * 30, 0), "hh:nn")
strSQL = "UPDATE tbl_Email_Rolling "
strSQL = strSQL & "SET ModifiedDate = DATEVALUE([ModifiedDateTime]), "
strSQL = strSQL & "ModifiedPeriod = '" & strTime & "'"

Debug.Print strSQL

DoCmd.RunSQL strSQL
End Sub

Thank You
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

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