473,404 Members | 2,213 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,404 software developers and data experts.

how add totaltime = [hh:mm:ss] + [hh:mm:ss] in query

547 512MB
how add (longtime) totaltime = [hh:mm:ss] + [hh:mm:ss] in query;
i need to be able to add more than 24hrs also but it can still show in this format
ie (hh:mm:ss) 31:10:20 = 31hrs 10min 20sec
pls help
Oct 16 '10 #1

✓ answered by OldBirdman

OK, so the times are not stored as date/time data as suggested in the original post. They are stored as text (string) data. The operand + (plus) adds numeric data, but concatinates string data. That is what is happening here. Your total time "01:09:4701:10:09" is "01:09:47" concatinated with "01:10:09".
Therefore, what you need to do is convert these strings to date/time before adding. CDate([MultidayOneQ.Racetime]) + CDate([MultidayTwoQ.Racetime]) would add these as times, not strings. You will still have to convert this sum to your custom format.

11 7416
NeoPa
32,556 Expert Mod 16PB
You just add them together.

With so little background information or any sort of explanation about what you're working with I have nothing to go further with.
Oct 16 '10 #2
OldBirdman
675 512MB
Times and dates are stored as numbers, with the fractional part as the time, and the integer part as the date. Adding 0.75 (6:00:00PM) to 0.5(Noon) results in 1.25. Formatting, whether longtime or shorttime or any other formatting is applied to display the stored data (number)in a meaningful form.
Adding two times in a query is as NeoPa suggests, just add them.
Access does not have a built-in format for displaying time as hours/minutes/seconds when the total hours exceeds 24, which is when the fractional parts sum to a value greater than 1. Therefore, this will require a user function to accept as a parameter a long number.
This function would return '31hrs 10min 20sec' or '4239hrs 0min 0sec' or ANY other valid hrs/min/sec as a string.
Remember, you are dealing with the way times are stored in the query, and the way you want the times formatted when shown.

OldBirdman
Oct 16 '10 #3
neelsfer
547 512MB
this is what i get
TotalTime:[MultidayOneQ.Racetime]+[MultidayTwoQ.Racetime]
IDNo -----------Day1------- Day2--------TotalTime
7805085171085 --01:09:47---01:10:09-----01:09:4701:10:09

i get the Day1 and Day2 results by filtering the racetimingT in two separate queries (using a 1 or 2 linked to a day, that is added when race is setup). then In another query i link each day's IDNo to the IDNO from the cyclist table. This is only way i can get the records to display from "vertical to horizontal" in a query and separated per day

i added --- in the spaces
Oct 16 '10 #4
OldBirdman
675 512MB
OK, so the times are not stored as date/time data as suggested in the original post. They are stored as text (string) data. The operand + (plus) adds numeric data, but concatinates string data. That is what is happening here. Your total time "01:09:4701:10:09" is "01:09:47" concatinated with "01:10:09".
Therefore, what you need to do is convert these strings to date/time before adding. CDate([MultidayOneQ.Racetime]) + CDate([MultidayTwoQ.Racetime]) would add these as times, not strings. You will still have to convert this sum to your custom format.
Oct 16 '10 #5
neelsfer
547 512MB
thx a million
if i add a day3 and day4 in calculation but there is no data in there yet, should i use Nz or? because i get datatype mismatch error in criteria expression if datafield is blank
Oct 16 '10 #6
NeoPa
32,556 Expert Mod 16PB
Nice one OB :-)

@Neelsfer - I'd suggest post #5 as the Best Answer ;-)
Oct 16 '10 #7
OldBirdman
675 512MB
I think this is a new question, and belongs in a new thread. However, as asked, it is incomplete and would not be understood.

Your table(s) are not normalized. I see over and over suggestions by experts that this not be allowed to happen, but each poster feels is circumstance is unique, and non-normalized tables are justified. Just ranting here.

Because you are storing time as text, it is up to you to verify that the string actually represents a time. Nz() certainly will correct fields whose value is null, which is in the table design for an initial value for the field. Why not "00:00:00" instead? You don't say how the data is entered and/or verified, so you also may need other corrections.
Oct 16 '10 #8
neelsfer
547 512MB
The CDate works to add the 00:00:00 but it stops at 12pm and start all over again. it also shows AM
03:07:10 AM + 07:00:06 AM + 04:02:42AM = 02:09:58 AM
I even appended this query into a table with longdate fields but it is still the same

The way i added it + filtered is probably why its so complicated.
Its for a 3 day cycling race. I captured it in a subform: the racedate and DayNo and racetime (calculated) are both in same table ie 1 or 2 or 3. The data is then filtered depending on the day and added up.
any suggestions pls?
Oct 18 '10 #9
OldBirdman
675 512MB
Converting your time strings to dates using CDate is good, providing you verify that the string is a time, as I mentioned before.
But dates are stored as 64-bit (8-byte) floating-point numbers. Positive values to the left of the decimal point represent the number of days starting with 30 Dec 1899 through 31 Dec 9999. The values to the right of the decimal represent time, in fractions of a day. .5 is 1/2 of a day, or midday, and .75 is 3/4 of a day, or 6:00:00PM.
You are using date fields to represent elapsed time, not a time of a day. This is done all the time, but when you do arithmetic, you must realize that Access inteprets 0.75 as 12/30/1899 06:00:00PM. Adding this to 0.5 (012/30/1899 12:00:00PM) will result in 1.25 or 12/31/1899 06:00:00AM. Formatting as longdate does not change this, only changes what is displayed, not the underlying values.
I tried your calculation in the Immediate Window, using CDate and here Copy/Paste exactly what happened:
Expand|Select|Wrap|Line Numbers
  1. ?CDate("03:07:10 AM") + CDate("07:00:06 AM") + CDate("04:02:42AM")
  2. 2:09:58 PM 
I have no idea what you did. Actually, I have no idea what you are doing, or what you tried, or what the queries you refer to are. You have not chosen to share any code or SQL with us.
Oct 18 '10 #10
neelsfer
547 512MB
Sorry i am a beginner with this vb; probably done it totally wrong;
This problem originates from

Racedetail tbl where i add the race details
1. Racename (txt)
2. racedate (datefield)
3.distance (numberfield
4. dayno (numberfield) (usually day1 or 2 or 3 of race)
5. actualstartime (longtime)

Then have racetiming tbl fields
racetimingid (autonumber)
Racename (txt)
racedate (date)
finishseq (number)
Finishtime (longtime)

In query i have [finishtime]-[actualstarttime] = racetime per "raceno which is linked to cyclist on that specific date
The problem is that it can be a multiday race, so i have to filter results by dayno in racedetail tbl (all day 1 or 2 or 3 results together)and then add them together as totaltime per cyclist. this is where data problem originates from.
hope its clear now.thx for help so far
Oct 18 '10 #11
OldBirdman
675 512MB
I'm sorry, but I have no idea what is going on here. This question is related to new-sequential-no-required and I don't know what you are asking there either.
One problem are the terms 'add', 'added', and '+'. "...., and a 1 is added to LapNo field" is confusing. Are you adding a 1 to the existing value already in the LapNo field, placing a 1 in the field, or adding a record to a table with a key 1 greater than the previous key, or something else?
You can have only one race per day, presumably stored in racedate, but it can be a multiday race. Both racedate and Racename are in both tables, therefore this project is not normalized. Somewhere you also have raceno, which is the cyclistnumber, but I don't find it in your tables.
I have looked at both these threads, and do not know what this project is supposed to achieve, so I cannot offer any further guidance there.
I see no code or SQL, so I don't know what specifically you are struggling with, so I cannot help there either. I've tried guessing what you need, but with no feedback I don't know if I'm helping.

Maybe someone else can be of more help than I can.

OldBirdman
Oct 18 '10 #12

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

Similar topics

8
by: Assimalyst | last post by:
Hi i have a value entered into an asp text box, procedureDateTxtBx.Text, thet has the format dd/MM/yyyy. I need to convert this into a format recognisable by SQL server in order to properly query...
3
by: jobi | last post by:
Hi, I've tried to get to this formatting stuff once, a while ago. I still didn't figure out how to format a date-column in a (data)-grid. I have a dynamic query that returns a # of columns....
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
7
by: mr.nimz | last post by:
hello, this is antenio. recently i've come to a problem. i got a way through it, somehow, still it left me in a curious state, so i'm posting it here, if i can get an answer from some techy, ...
1
seshu
by: seshu | last post by:
Hi every body to morning my cousine has show his application and also his live db in that to sav the length of all the voice files he has saved in time format ie he took the datatype of time now i...
2
by: progvar | last post by:
Hi! i am running the query but it is showing the error of syntax, i m accessing this table from sql server & my query is squery = "SELECT * FROM New_Rec where From_Date > = " & Format(DTPFrom &...
2
by: smitanaik | last post by:
hi i want to do validation of datetime in javascripti.e is i want it in this format dd:mm:yyyy:hh:mm:ss plz heklp me out its urgent
2
by: impin | last post by:
i have stored the user break times in the database... user break start time and end time... the timestamp stored in the database in the (yyyy-mm-dd hh:mm:ss) format in the database... when i...
4
by: neelsfer | last post by:
I first deducted the laptime and actualstarttime of a race in a query using this formula and it gives me a correct lap1time value Lap1Time:nz(Format(-,"hh:nn:ss")) = 00:51:54 if i repeat this...
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.