473,385 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Converting a number into time

15
Hello,
I have a access query that reads in 2 time fields but its not in time format. Example: 900, 1300, 256, 2245, etc. What I am trying to do is driver comes in at 900(9:00AM) and leaves at 1300(1:00PM). Then have it give me the total time he was here, 4 hours

The build expression is as follows:

Total Time:
IIf([CARRIER_OFF_DOCK_TIME]>959,TimeSerial(Mid([CARRIER_OFF_DOCK_TIME],1,2),Mid([CARRIER_OFF_DOCK
_TIME],3,2),0),TimeSerial(Mid([CARRIER_OFF_DOCK_TIME],1,1),Mid([CARRIER_OFF_DOCK_TIME],2,2),0)) - IIf([CARRIER_ON_DOCK_TIME]>959,TimeSerial(Mid([CARRIER_ON_DOCK_TIME],1,2),Mid([CARRIER_ON_DOCK
_TIME],3,2),0),TimeSerial(Mid([CARRIER_ON_DOCK_TIME],1,1),Mid([CARRIER_ON_DOCK_TIME],2,2),0))

That should work but I get an error: "Data type mismatch in criteria expression."

The last thing I should mention is that I have no control over the time being read into the query. Its link to a table outside of Access.

Any insight would be great.
Thx,
John
Nov 12 '07 #1
4 10900
FishVal
2,653 Expert 2GB
Hi, John.

Try the following to convert [CARRIER_ON_DOCK_TIME] to time:
Expand|Select|Wrap|Line Numbers
  1. TimeSerial([CARRIER_ON_DOCK_TIME]/100, [CARRIER_ON_DOCK_TIME] mod 100, 0)
  2.  
Note that subtracting one date from another gives by default difference in days. To convert it to hours you may use Format() function
Expand|Select|Wrap|Line Numbers
  1. Format (TimeSerial([CARRIER_OFF_DOCK_TIME]/100, [CARRIER_OFF_DOCK_TIME] mod 100, 0) - TimeSerial([CARRIER_ON_DOCK_TIME]/100, [CARRIER_ON_DOCK_TIME] mod 100, 0), "h")
  2.  
or
Expand|Select|Wrap|Line Numbers
  1. Format (TimeSerial([CARRIER_OFF_DOCK_TIME]/100, [CARRIER_OFF_DOCK_TIME] mod 100, 0) - TimeSerial([CARRIER_ON_DOCK_TIME]/100, [CARRIER_ON_DOCK_TIME] mod 100, 0), "hh:mm")
  2.  
to get hours and minutes

or simply multiply the result on 24
Expand|Select|Wrap|Line Numbers
  1. (TimeSerial([CARRIER_OFF_DOCK_TIME]/100, [CARRIER_OFF_DOCK_TIME] mod 100, 0) - TimeSerial([CARRIER_ON_DOCK_TIME]/100, [CARRIER_ON_DOCK_TIME] mod 100, 0))*24
  2.  
Regards,
Fish
Nov 12 '07 #2
jrayjr
15
Thanks Fish,
I will give it a try and post back.

-John
Nov 12 '07 #3
jrayjr
15
Thanks Fish, its work but I have to work with it alittle. Some of the values for the Total Time are incorrect but most are right.

Expand|Select|Wrap|Line Numbers
  1. Format (TimeSerial([CARRIER_OFF_DOCK_TIME]/100, [CARRIER_OFF_DOCK_TIME] mod 100, 0) - TimeSerial([CARRIER_ON_DOCK_TIME]/100, [CARRIER_ON_DOCK_TIME] mod 100, 0), "hh:mm")
  2.  
Example:

1537 - 1658 = 02:21 is incorrect
2213 - 59 = 20:14 is incorrect
1411 - 1646 = 2:35 correct
601 - 1033 = 4:32 correct

So I may have to use conditional statements for when the time rolls into a new day too. If you have any ideas that would be great.

Thx,
John
Nov 13 '07 #4
FishVal
2,653 Expert 2GB
Hi, John.

The following code will work correctly.

Expand|Select|Wrap|Line Numbers
  1. Format (TimeSerial(int([CARRIER_OFF_DOCK_TIME]/100), [CARRIER_OFF_DOCK_TIME] mod 100, 0) - TimeSerial(int([CARRIER_ON_DOCK_TIME]/100), [CARRIER_ON_DOCK_TIME] mod 100, 0), "hh:mm")
  2.  
Nov 13 '07 #5

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

Similar topics

3
by: Nikola | last post by:
Hi all, I have a problem converting datetime to integer (and than back to datetime). Depending whether the time is AM or PM, same date is converted to two different integer representations,...
1
by: renee_ld | last post by:
In a query I used the function datediff to calculate the number of minutes between two time periods on a given day. This function returned the number of minutes as a long integer data type. I...
30
by: zexpe | last post by:
I have an extremely cpu/data intensive piece of code that makes heavy use of the following function: void convertToDouble(const std::string& in, double& out) { out = atof(in.c_str()); } I...
3
by: NateM | last post by:
How do I convert any given date into a milliseconds value that represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT? Is there an easy way to do this like...
59
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when...
7
by: Tor Aadnevik | last post by:
Hi, I have a problem converting values from Single to double. eg. When the Single value 12.19 is converted to double, the result is 12.1899995803833. Anyone know how to avoid this? Regards...
4
by: Chris Asaipillai | last post by:
Hi there My compay has a number of Visual Basic 6 applications which are front endeed onto either SQL Server or Microsoft Access databases. Now we are in process of planning to re-write these...
28
by: Randy Reimers | last post by:
(Hope I'm posting this correctly, otherwise - sorry!, don't know what else to do) I wrote a set of programs "many" years ago, running in a type of basic, called "Thoroughbred Basic", a type of...
3
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying...
18
by: Dirk Hagemann | last post by:
Hello, From a zone-file of a Microsoft Active Directory integrated DNS server I get the date/time of the dynamic update entries in a format, which is as far as I know the hours since january 1st...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.