473,503 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Difference from two time fields: MS Access

Dököll
2,364 Recognized Expert Top Contributor
Hey Guys!

I ran into a puzzle; below query gets me what I need (Difference from two time fields) in Ms Access 2000 but not in MS Access 2003, any idea why:

Expand|Select|Wrap|Line Numbers
  1. SELECT Data.ID, Data.GetTextFromText, Data.Stamp, DateDiff("h",[Stamp],[GetTextFromText]) AS HoursFromTimes
  2. FROM Data;
  3.  
Thanks for your help!

Dököll
Mar 25 '08 #1
10 2339
missinglinq
3,532 Recognized Expert Specialist
Missing reference in the 2003 set up?

Linq ;0)>
Mar 25 '08 #2
Dököll
2,364 Recognized Expert Top Contributor
Missing reference in the 2003 set up?

Linq ;0)>
Hey there missinglinq!

I am not sure how you mean. Do you suppose when this version was installed something was not added?

What's the remedy for that, if this is the case?

Thanks for replying!

Dököll
Mar 27 '08 #3
missinglinq
3,532 Recognized Expert Specialist
As time goes by in a given installation/version of Access, new features/functions are needed, and in order to provide some of them, new refernce libraries are added. We tend to forget this as time goes by and we get use to using these functions automatically. But a new installation only installs the very basic libraries, and so some of the needed libraries may be missing. Here's a link to Allen Browne's paper on checking for this kind of probelm and fixing it:

http://allenbrowne.com/ser-38.html

Anytime you have functions/code that's been working fine and it breaks when you move to another installation/version on the same PC, you need to think about missing references. Also moving an app to another machine and having it break calls for checking the references. I have even heard of cases where applying service packs have caused this problem, but can't remember the version/SP involved.

Linq ;0)>
Mar 27 '08 #4
Dököll
2,364 Recognized Expert Top Contributor
http://allenbrowne.com/ser-38.html

Anytime you have functions/code that's been working fine and it breaks when you move to another installation/version on the same PC, you need to think about missing references....

Linq ;0)>
Much appreciated assistance, will check into it. I see what you mean now, the code works here just fine, running 2000 Premium, when I load it to 2003, I get strange readings, you know 94375643 as opposed to one digit.

Thanks again!

Dököll
Mar 28 '08 #5
Dököll
2,364 Recognized Expert Top Contributor
Much appreciated assistance, will check into it. I see what you mean now, the code works here just fine, running 2000 Premium, when I load it to 2003, I get strange readings, you know 94375643 as opposed to one digit.

Thanks again!

Dököll
Added info...

I figured perhaps mentioninf what I truly hope to achieve may give me a better idea...

Data added to a database carries date and time, and I have skillfully matestred the date portion where/if date is less than todaydate, user gets a pop up

But if time is after 4 PM even if date is less than todaydate, user does not get a pop.

So in order to achieve this I need to first grab time out of the data:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'We need to do additional checking to see what time data being added in
  3. 'Below creates a file with the data added and reads the file to find time partially hard-coded in if statement
  4. '" 7:0": Notice space between first open quote and actual number
  5. 'This is important to make sure we are getting hours and not minutes
  6. 'Time may be as 1:57:01 AM, if 1 is not in code and 7 is recorded in code as number/digit to find
  7. '"1:57:01", results in 7:01 AM.  In this case, we add a space to open quote so application looks
  8. 'for a space before the number, therefore 02/02/2008 1:57:01, from 2008 to 1
  9. 'in code we will always get 1 o'clock
  10.  
  11.  
  12. Dim FileNum1
  13. FileNum1 = "C:\ACCESS_2_TXT\usermate.txt"
  14. Open FileNum1 For Output As #1
  15.  
  16.  
  17. 'We are creating the file with both the IssuesItems and Email texboxes
  18. 'This is important because data added to IsuesItems (Email message, log scans, pre processors textbox) will have dates
  19. 'This is important because data added to Email textbox (Name, Email, Date/Time) will have dates
  20.  
  21.  
  22. Print #1, Items.Value 'this will recorde data and time values
  23. Print #1, Email.Value  'this will recorde data and time values
  24.  
  25.  
  26.  
  27. Close #1
  28. Me.Items.SetFocus
  29.  
  30.  
  31. 'We are reading the file with both the IssuesItems and Email texboxes
  32. 'This is important because data added to IsuesItems (Email message, log scans, pre processors textbox will have dates
  33. 'This is important because data added to Email textbox (Name, Email, Date/Time) will have dates
  34.  
  35.  
  36. Dim GoSplit As Variant, FileName1, f
  37. Dim strGetTime As String
  38. FileName1 = "C:\ACCESS_2_TXT\\usermate.txt"
  39. f = FreeFile
  40. Open FileName1 For Input As #1
  41. Do While Not EOF(f)
  42. Line Input #1, strGetTime
  43. GoSplit = Split(strGetTime, " ")    
  44.  
  45. 'Function looks within file as string, reads the string to find instances of the digit(s) in code
  46. '" 7:0": Notice space between first open quote and actual number
  47. 'This is important to make sure we are getting hours and not minutes
  48. 'Time may be as 1:57:01 AM, if 1 is not in code and 7 is recorded in code as number/digit to find
  49. '"1:57:01", results in 7:01 AM.  In this case, we add a space to open quote so application looks
  50. 'for a space before the number, therefore 02/02/2008 1:57:01, from 2008 to 1
  51. 'in code we will always get 1 o'clock
  52.  
  53.  
  54. If InStrB(strGetTime$, " 7:0") <> 0 And InStrB(strGetTime, " AM") <> 0 Then 'Function that check time from textboxes that hold time and time...
  55. GetTextFromText.Value = "7:00 AM"
  56. 'Me.GetTextFromText.Value = Format(Me.Stamp.Value - Me.GetTimeFromText.Value, "hh:mm")
  57. End If
  58.  
  59.  
This is working, but when I get say 7:00 I want to comapre against the TimeStamp, thus 7:00 - the TimeStamp time would give me time elapsed in hours..

I do not want to write too much code for it, I know it is pretty simple I just cannot see, a quick attempt to make the database solid.

What are your thoughts? Thanks!

Dököll
Mar 29 '08 #6
JGilis
2 New Member
Hi

I've written a function on converting minutes to hh:mm format

So now the syntax in you query should just be this:

TimeFormat(datediff("n"; <starttime>; <endtime>))

This is the function just make a module (name not important)
and paste it in enjoy !

[HTML]Function TimeFormat(ParamArray FieldArray() As Variant)
'declaration
Dim hours As Single
Dim minutes As Integer
Dim totalminutes As Single
Dim I As Integer
'collect the minutes
totalminutes = CSng(FieldArray(0))
'the formula
hours = totalminutes / 60
'since cint rounds these day's ive created my own cint(or i'm just doing something wrong and i'm not smart)
If InStr(1, hours, ",") > 0 Then
'take all the character before the comma
I = InStr(1, hours, ",") - 1
hours = Left(hours, I)
End If
'formula for the minutes
minutes = totalminutes Mod 60
'Format them together
TimeFormat = Format(hours, "00") & ":" & Format(minutes, "00")

End Function[/HTML]
Apr 1 '08 #7
Dököll
2,364 Recognized Expert Top Contributor
Hi

I've written a function on converting minutes to hh:mm format

So now the syntax in you query should just be this:

TimeFormat(datediff("n"; <starttime>; <endtime>))

This is the function just make a module (name not important)
and paste it in enjoy !

Expand|Select|Wrap|Line Numbers
  1. Function TimeFormat(ParamArray FieldArray() As Variant)
  2.     'declaration
  3.     Dim hours As Single
  4.     Dim minutes As Integer
  5.     Dim totalminutes As Single
  6.     Dim I As Integer
  7.         'collect the minutes
  8.         totalminutes = CSng(FieldArray(0))
  9.         'the formula
  10.         hours = totalminutes / 60
  11.         'since cint rounds these day's ive created my own cint(or i'm just doing something wrong and i'm not smart)
  12.         If InStr(1, hours, ",") > 0 Then
  13.             'take all the character before the comma
  14.             I = InStr(1, hours, ",") - 1
  15.             hours = Left(hours, I)
  16.         End If
  17.         'formula for the minutes
  18.         minutes = totalminutes Mod 60
  19.         'Format them together
  20.         TimeFormat = Format(hours, "00") & ":" & Format(minutes, "00")
  21.  
  22. End Function
Much appreciated, JGilis!

Will give it a go:-)
Apr 3 '08 #8
Dököll
2,364 Recognized Expert Top Contributor
Hi

I've written a function on converting minutes to hh:mm format

So now the syntax in you query should just be this:

TimeFormat(datediff("n"; <starttime>; <endtime>))

This is the function just make a module (name not important)
and paste it in enjoy !

[HTML]Function TimeFormat(ParamArray FieldArray() As Variant)
'declaration
Dim hours As Single
Dim minutes As Integer
Dim totalminutes As Single
Dim I As Integer
'collect the minutes
totalminutes = CSng(FieldArray(0))
'the formula
hours = totalminutes / 60
'since cint rounds these day's ive created my own cint(or i'm just doing something wrong and i'm not smart)
If InStr(1, hours, ",") > 0 Then
'take all the character before the comma
I = InStr(1, hours, ",") - 1
hours = Left(hours, I)
End If
'formula for the minutes
minutes = totalminutes Mod 60
'Format them together
TimeFormat = Format(hours, "00") & ":" & Format(minutes, "00")

End Function[/HTML]
Hello JGilis!

This was truly helpful, I was able to make fit my needs... To tell you the truth new management has made it possible to no longer have to seek dates nor have a report rendered; but wanted to thank you anyway for all your help, nice of you. Have a great week-end!
Apr 18 '08 #9
puppydogbuddy
1,923 Recognized Expert Top Contributor
Hi Dokoll,

If you are interested in date/time stamping and maintaining a log table for your transactions, then this excellent code from the tips page of
www.aadconsulting.com should help you out.

Audit Trail for Table Records

In a Data Form:

Private Sub Form_BeforeUpdate(Cancel As Integer)

'Purpose: Timestamp current form record
'Field Controls:
'LastEdit - General Date DataType
'DateAdded - General Date DataType
'CreatedBy - Text DataType
'LastEditBy - Text DataType

On Error GoTo RecStamp_Error

Me.LastEdit = Now
Me.LastEditBy = GetUser()

' Only stamp DateAdded and CreatedBy fields if a new record
If Me.NewRecord Then
___Me.DateAdded = Now
___Me.CreatedBy = GetUser()
End If

RecStamp_Exit:

Exit Sub

RecStamp_Error:

MsgBox Err.Description
Resume RecStamp_Exit

End Sub


In a Code Module:


Option Compare Database
Option Explicit

Public Declare Function GetUserName _
Lib "Advapi32.dll" Alias "GetUserNameA" _
(ByVal ABuffer As String, nSzie As Long) As Long

Public Function GetUser() As String
'Returns Windows User LogOn ID
On Error GoTo GetUser_Err

Dim sUserName As String
Dim lSize As Long
Dim lLength As Long

sUserName = String(15, " ")
lSize = Len(sUserName)
lLength = GetUserName(sUserName, lSize)
GetUser = Left(sUserName, lSize - 1)

Exit Function
GetUser_Err:

GetUser = "Unknown"
Exit Function

End Function
Apr 20 '08 #10
Dököll
2,364 Recognized Expert Top Contributor
Hey this is very cool puppydogbuddy!

I will keep it in my library and also send to the group...

Have a wonderful week-end:-)
Apr 26 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2309
by: Bjřrn T Johansen | last post by:
I need to compute the difference of Time fields, in the format HHMM. Is it possible to do the math in the Select? Regards, BTJ --...
1
9191
by: mark | last post by:
I'm stuck: In a query I am trying to compare two fields with a date/time data type and a LongTime format to get the difference in hours (minutes and seconds if possible). After that I need to...
6
3368
by: Tony Williams | last post by:
SORRY I know we shouldn't do this but I'm desperate for an answer to this and the previous post didn't seem to get a response. I have a table with two fields, txtvalue (a number field) and...
5
8722
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
2
3542
by: Amit | last post by:
Hello, I have a class where I store a lot of setting names. Right now they're all declared as consts : public const CurDoc as string = "CURRENT_DOCUMENT" From what I know about const, every...
0
1236
by: 362315 | last post by:
I am receiving the following error: Microsoft Visual Basic Run-Time error '2147467259 (80004005)': The microsoft jet database engine cannot open the file. It is already opened exclusively by...
5
1447
by: bobh | last post by:
Hi All, Is there a difference in preformance between the two; TblNme has 36 fields across a record a query that selects all fields and the report only uses 75% of the fields, ie; Select...
3
3424
by: Steve | last post by:
I am trying to calculate elapsed travel times for flights. My plan is to enter the local departure time, the departure city and the local arrival time and city. These times would be standardised...
4
3837
by: Quizzed | last post by:
Hi, Using MS Access 97, i have a query over an As/400 which returns a number of fields. Within each record returned, two fields are of numeric data type but contain values relating to time. The...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.