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

need to convert text to time only

hmm...

I have something similar to this but in my case this will not work. I have a text field storing the value in mins in this format 000100 representing 1 min.

I need to break this into a time reference 00:01:00 so that I can use it to calculate total time spent.

I have tried several different date/time functions but they all add the date, which I do not need.

question is: is there a way to convert this text into a time only field ?

i.e. Duration time/duration
005005 ... 00:50:05
000905 ... 00:09:05
001500 ... 00:15:00

total 01:14:10

thanks for you help!
Aug 30 '07 #1
13 15772
puppydogbuddy
1,923 Expert 1GB
hmm...

I have something similar to this but in my case this will not work. I have a text field storing the value in mins in this format 000100 representing 1 min.

I need to break this into a time reference 00:01:00 so that I can use it to calculate total time spent.

I have tried several different date/time functions but they all add the date, which I do not need.

question is: is there a way to convert this text into a time only field ?

i.e. Duration time/duration
005005 ... 00:50:05
000905 ... 00:09:05
001500 ... 00:15:00

total 01:14:10

thanks for you help!
Try >>>>> TimeValue([YourDateTimeField])
Aug 30 '07 #2
Scott Price
1,384 Expert 1GB
hmm...

I have something similar to this but in my case this will not work. I have a text field storing the value in mins in this format 000100 representing 1 min.

I need to break this into a time reference 00:01:00 so that I can use it to calculate total time spent.

I have tried several different date/time functions but they all add the date, which I do not need.

question is: is there a way to convert this text into a time only field ?

i.e. Duration time/duration
005005 ... 00:50:05
000905 ... 00:09:05
001500 ... 00:15:00

total 01:14:10

thanks for you help!
Probably the easiest way is to go into the table design view and change the input mask for your column Duration to Long Time. The mask will end up looking like this: 99:00:00\ >LL;0;_

This will also ensure that any future data entered in this field conforms to the same format also.

Regards,
Scott
Aug 30 '07 #3
Ahh yes I agree with both of you in regards to changing the data type in the table, however, part of the problem is that I am working with a proprietary program and the DB I use is a read only copy of a live DB.

so I have to convert it in the query; either a straight query or an append query

I even resorted to trying to modify a built in function:

TOD: TimeSerial ((Hour(Left([duration],2), (Mid([duration],3,2), (Mid([duration],5,2))))

and get a type mismatch error...surely there is a way to accomplish this.

<edit>just to be sure I tried the timevalue again and it just shows an error in the column
Aug 30 '07 #4
puppydogbuddy
1,923 Expert 1GB
Ahh yes I agree with both of you in regards to changing the data type in the table, however, part of the problem is that I am working with a proprietary program and the DB I use is a read only copy of a live DB.

so I have to convert it in the query; either a straight query or an append query

I even resorted to trying to modify a built in function:

TOD: TimeSerial ((Hour(Left([duration],2), (Mid([duration],3,2), (Mid([duration],5,2))))

and get a type mismatch error...surely there is a way to accomplish this.

<edit>just to be sure I tried the timevalue again and it just shows an error in the column

Try this link and see if it helps (go to the section for computing elapsed time):

http://office.microsoft.com/en-us/ac...102181033.aspx
Aug 30 '07 #5
missinglinq
3,532 Expert 2GB
Converting 005005 to 00:50:05 is relatively easy!

format("005005","00:00:00")

The complicated part is the adding! The problem is that neither 005005 nor 00:50:05 is really time! Time is a part of date. I think what you need to do is to parse out the data you already have, i.e. 005005, into seconds, add all these seconds together and then convert the results into hrs/mins/secs. Assuming that duration is the field that holds the data you start with

(left(duration,2)*3600) + (mid(duration,3,2)*60) + right(duration,2)

will give you the total seconds for each duration. You then total up all the seconds and put the total in a function to break it down into the hrs/mins/secs.

If this sounds right to you, I already have a function to do this.

Linq ;0)>
Aug 30 '07 #6
Denburt
1,356 Expert 1GB
Ling is correct yet try this It should tend to your needs and return an actual time.

I used [re] instead of your [duration] field name quicker for me to verify,

TimeSerial(Left([re],2),Mid([re],3,2),Right([re],2))

The actual query I used was as such.

Expand|Select|Wrap|Line Numbers
  1. SELECT Table1.re, TimeSerial(Left([re],2),Mid([re],3,2),Right([re],2)) AS 12
  2. FROM Table1;
Aug 30 '07 #7
awesome!!!

Thank you very much for all the help!

You guys are great!
Aug 30 '07 #8
Denburt
1,356 Expert 1GB
Glad to help the string you were using was real close if you compare the two I think you will see the difference.
Aug 30 '07 #9
missinglinq
3,532 Expert 2GB
Here's the function to convert seconds into hours/minutes/seconds HH:MM:SS.

In the Objects Dialog box click on Modules
Click on New
Paste this code in
Expand|Select|Wrap|Line Numbers
  1. Public Function TimeParsing(TotalSeconds As Long) As String
  2. 'Parses seconds into Hours-Minutes-Seconds in HH:MM:SS format
  3. Dim HoursLapsed, SecondsLeft, MinutesLapsed, SecondsLapsed As Long
  4.  
  5. HoursLapsed = Int(TotalSeconds / 3600)
  6. SecondsLeft = TotalSeconds Mod 3600
  7.  
  8. MinutesLapsed = Int(SecondsLeft / 60)
  9. SecondsLapsed = SecondsLeft Mod 60
  10.  
  11. TimeParsing = Format(HoursLapsed, "00") & ":" & Format(MinutesLapsed, "00") & ":" & Format(SecondsLapsed, "00")
  12.  
  13. End Function
  14.  
Save the module and when prompted, name it TimeConversion.

To use the function do something like this

Expand|Select|Wrap|Line Numbers
  1. YourTimeTotalsField = TimeParsing(TimeInSeconds)
where YourTimeTotalsField is the field to hold the parsed string (in hh:mm:ss format) and TimeInSeconds is your field holding the total of all seconds.

Linq ;0)>
Aug 30 '07 #10
Thank you Linq, this works great!
Aug 30 '07 #11
missinglinq
3,532 Expert 2GB
Glad we could help!

Linq ;0)>
Aug 30 '07 #12
This is such an old post, but wanted to thank you becaue i have been searching online for days and this was the solution that worked for me. Thanks!
May 16 '12 #13
NeoPa
32,556 Expert Mod 16PB
We understand Silvia, and we're always happy for old threads to be dug up to drop in a "Thank you". It's always welcome and reminds us that old threads are still helpful to people, even if the original contributors to the thread don't need it any more :-)
May 17 '12 #14

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

Similar topics

3
by: Erwin Bormans | last post by:
Hello I want to convert a value in a text propertie to a double. I can use CDbl(grid1.text) for this, but the problem is that some text properties are empty and when they are the code give...
4
by: Daniel Köster | last post by:
Is there someone who has got some tips on how to convert text encoded with character referense ({) to unicode or uft-8 format using VB.net? Is there a function or something that can help with the...
8
by: Chris | last post by:
Sorry, This should be simple, but brain is hurting... How do I convert a Current Time to a Decimal 6,0 (HMS)? There must be a cleaner way then this: Insert into Table Values Dec(...
3
by: Francesc | last post by:
Hi, I'm new at this newsgroup and I want do ask some questions and opinions about this subject. I'm developing an application focused in a very specific task: clean and labelling text documents...
1
by: XML newbie: Urgent pls help! | last post by:
How to Convert local time(eg EST) on local machine to GMT. I am using VB.Net 2005. Then I need to subtract 1 minute(or 1-100) minute selected by the user in the combobox and pass it as start...
2
by: ElizaInternet | last post by:
I need convert NITF Xmls for insert into BD SQL. I try convert to file text and then insert into BD I used the Syndication:NITF of perl for this convertion. Any have information about this??, I...
1
by: okaymy1112 | last post by:
I have data in this format 0800, 1730, 0930, etc. I do not know how to convert this time to read something like, 8:00AM, 5:30 PM, 9:30AM etc. Also I want to group things by day. I have courses...
1
by: rajendiran | last post by:
hi friends i will type any text in textbox. and chose any language that text will converted in that language example like english to french.. how to convert text like this anyone help me..........
4
by: ahmurad | last post by:
Dear Brothers, I am struggling the following four Date-Time type values which were inputted into MYSQL database in different tables. As MYSQL Default Time Format: YYYY-MM-DD HH:MM:SS, So I used...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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,...
0
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.