473,513 Members | 8,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert part of text string to Time

9 New Member
I have data that I import from an Excel sheet into Access. the field I have problems with is called [SaleTime]. It contains the date and time of the article being weighed. The string comes in like this:
20120314080253
I have two fields in my query. One converts the first part to a date and the other converts the second part to Time. It works great in Access.

Weigh_Date: DateSerial(Left([SaleTime],4),Mid([SaleTime],5,2),Mid([SaleTime],7,2))

Weigh_Time: TimeSerial(Right(Left([SaleTime],10),2),Right(Left([SaleTime],12),2),Right([Saletime],2))

My problem is when I create an ODBC link to a new sheet in Excel, the time shows as 12:00:00 AM in all the fields.

What am I doing wrong?

Thanks a lot, Sharon
May 13 '12 #1
18 5160
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Are you adding these 2 values together and storing them in a single field in access? Access has one field type called DateTime used for storing both date and time information. Both can (and I would think in most cases should) be stored in only 1 field. It sounds like your export is only exporting the date part.
May 13 '12 #2
NeoPa
32,557 Recognized Expert Moderator MVP
If you're linking to a new sheet then I expect there is no data therein. 12:00:00 AM (or midnight) is actually the time-equivalent of 0.
May 14 '12 #3
SharonH
9 New Member
Hi there. I am trying to Create a Date Field and a separate Time Field. The client needs to extract data based upon Time (the staff work in shifts). I have now realized, after using Microsoft Query, that the data actually comes in like this:
09/03/2012 12:00:00 AM (Date Field)
and the Time field looks like this: 00/01/1900 12:00:00 AM.
I am totally stumped.
Can you help? Thanks in anticipation :)
May 14 '12 #4
SharonH
9 New Member
Hi NeoPa. I'm linking the Access query to Excel sheets that I wanted to have the system update automatically so the user just needed to open Excel to have the latest data at his fingertips.
May 14 '12 #5
NeoPa
32,557 Recognized Expert Moderator MVP
I'm sure your thinking makes sense Sharon. Unfortunately, your explanation is still very ambiguous so it's hard to know where/how to help you.
May 14 '12 #6
SharonH
9 New Member
Hi NeoPa. OK, I shall try to explain it better. The data comes from a scale (it weighs sugar packages to ensure the weight is within limits). The scale data links to Excel. I then import the raw data into Access.
It is important that I create a date field as a separate field and a time field as a separate field in order to analyse the data. The date from the raw data looks like this and imports to Access as text: 20120308110024 which is basically yyyymmddhhmmss.

I need to separate this "text number" into two separate fields. In other words, extract the first 8 numbers to create a new Weigh Date field in the date format dd/mm/yyyy. Then I need to extract the last 6 numbers to create a new Weigh Time field in the time format of hh:mm:ss.

The date field needs to be dd/mm/yyyy and the time field needs to be hh:mm:ss.

The query I have reads as follows:
Expand|Select|Wrap|Line Numbers
  1. Weigh_Date: DateSerial(Left([SaleTime],4),Mid([SaleTime],5,2),Mid([SaleTime],7,2))
  2. Weigh_Time: TimeSerial(Right(Left([SaleTime],10),2),Right(Left([SaleTime],12),2),Right([Saletime],2))
When I check the query in Access it looks perfect but after linking the query to Excel, the data actually looks like this:

Weigh_Date: dd/mm/yyyy hh:mm:ss The Date is correct (ie: 09/03/2012 but the time is just zeros (ie: 00:00:00)

The Weigh_Time in excel comes in with the time and the date wrong (ie: 00/01/1900 00:00:00)

It isn't separating the Date info and the time info into two separate fields and it isn't reading the date or the time correctly when linking the data from Access to Excel.

I don't know what to do. I am thinking of bringing the data directly into Excel but that will ultimately create a HUGE file.

I hope this makes more sense? Regards, Sharon
May 15 '12 #7
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
If you open the excel sheet, and select the column where you have EXPORTED the Weigh_Time to, what is its format property set to?

If you change it to: Number with at least 4 decimal places, what values does it show?
May 15 '12 #8
SharonH
9 New Member
I haven't actually exported the data, I created an ODBC link from the Access DB to Excel but it comes is as a number format. When I change it looks fine but my Excel references to the data don't work.

However, I'm feeling rather clever at the moment. I have now done the following in my Access query. The only problem I am having now is the RealTm field. The time doesn't come into Excel correctly, it shows as "00/01/1900". I haven't been able to find a command like "CDate" to use for time. Any ideas? Here is my query:

Convert text number - Weigh_Date: DateSerial(Left([SaleTime],4),Mid([SaleTime],5,2),Mid([SaleTime],7,2))+TimeSerial(Right(Left([SaleTime],10),2),Right(Left([SaleTime],12),2),Right([Saletime],2))

Format as Date - WghDt: CDate([Weigh_Date])

Extract Date Part of field - RealDt: CDate(Left([WghDt],10))

Extract Time Part of field - RealTm: CDate(Right([WghDt],11))
May 15 '12 #9
NeoPa
32,557 Recognized Expert Moderator MVP
SharonH:
I hope this makes more sense? Regards, Sharon
It doesn't help much with the ambiguities I'm afraid Sharon. You make very clear what was already clear, which is your thinking and what you need to see, but give very little in the way of technical information that we can work with. Let me see if I can clarify what it is you need to explain better.

How do you access the data that is stored in an Excel spreadsheet from your Access database? You mention ODBC, importing and linking. I have no idea why ODBC might come into any part of this, and generally only one of linking and importing would be required (although I have a project where I use linked tables to import - but I'd never explain this situation without making those separate elements clear).

I'll assume that the layout of the sheet you're importing from is not too relevant at this stage, but how the data is stored in Excel is important. The format of the column is irrelevant for the process, but it may confuse you if it's not taken into consideration when you report how it's held in Excel. I suggest you focus on an individual cell from the sheet, make sure the format is set simply to General and the Horizontal Alignment also set to General then post what the value looks like in here. Ensure the column width is wider than the data then you can also indicate which side the data is aligned to. If it's on the right then we're dealing with numeric data and if on the left then string data. There is no need to save changes after getting this information.

When you have linked/imported the worksheet then please report here details of the field that has been created. We need the type and length characteristics.
May 15 '12 #10
SharonH
9 New Member
OK. Let me try. I'm using Office 2010. The data in Excel was brought in by clicking the Data Tab, then choosing "Get External Data" "From other sources". I then used Microsoft Query to bring the data from my Access query into my Excel spreadsheet.

All the columns have been formatted as General and they look like this:
Expand|Select|Wrap|Line Numbers
  1.    WghDt     RealDt  RealTm
  2. 40977.34219   40977   0
  3. 40977.34236   40977   0
All the figures are on the right side of the columns.

When I change the formatting of the columns to Date and Time, they look like this (also on the right).
Expand|Select|Wrap|Line Numbers
  1.    WghDt      RealDt      RealTm
  2. 09/03/2012  09/03/2012  12:00:00 AM
  3. 09/03/2012  09/03/2012  12:00:00 AM
Does that help?

Regards, Sharon

Sorry, it doesn't look good on this forum. I don't know how to paste it as a spreadsheet. I just use Control + V to paste.....
May 15 '12 #11
NeoPa
32,557 Recognized Expert Moderator MVP
One important point to remember, and I suspect it is at the heart of this issue somewhere or other, is that 32-bit long values only go up to 2 GB if signed and still only 4 GB if unsigned. That's ten decimal places at most. Eight places of date plus six of time come to fourteen DP. Unless we can force this into being seen as string data we will have serious problems reading these values.

Does that make the issue we're dealing with clearer Sharon? We need some precise technical information before we can look at a way of forcing Excel to behave itself.

** At this point I caught your post #9 which I'd missed earlier. **

An ODBC linked table? My system doesn't allow linking to Excel via ODBC. ODBC is very flexible so I cannot say it's impossible on your system, but I would ask why use ODBC for an Excel link when Access has inbuilt Excel connectivity (Instead of selecting ODBC you can select Microsoft Excel (*.xlsx; *.xls)) from Files of type:.

Regardless of that issue you are still falling over the problem of Excel trying to present the data numerically.
May 15 '12 #12
NeoPa
32,557 Recognized Expert Moderator MVP
Now there is a post #11 to respond to. I will prepare that but I think I need to put down a post marker in case you beat me to the punch again :-D
May 15 '12 #13
SharonH
9 New Member
Oops. Sorry. Getting a bit mixed up here :(
May 15 '12 #14
NeoPa
32,557 Recognized Expert Moderator MVP
SharonH:
Sorry, it doesn't look good on this forum. I don't know how to paste it as a spreadsheet. I just use Control + V to paste.....
Check out [code] Tags Must be Used. It will explain how to format code and/or tabular data.

From your post #11 it seems clear that the Date/Time data ([WghDt]) in Excel has come through fully, but it is neither text nor Long data, but Double (or Date/Time). This is good news. Try the following (assuming [WghDt] is in A2) :
[RealDt] - =DATEVALUE(TEXT(A2,"d mmmm yyyy"))
[RealTm] - =TIMEVALUE(TEXT(A2,"HH:mm:ss"))
May 15 '12 #15
SharonH
9 New Member
Hi NeoPa. Do I try your suggestion in Excel or in Access? Thanks, Sharon
May 15 '12 #16
NeoPa
32,557 Recognized Expert Moderator MVP
In Excel Sharon. The reference to A2 would only make sense in Excel.
May 16 '12 #17
SharonH
9 New Member
Hi NeoPa. Sorry I haven't got back to you earlier, but I was in the bush (wilderness) for the past 5 days.
Thanks, will try that.
Regards
Sharon
May 21 '12 #18
NeoPa
32,557 Recognized Expert Moderator MVP
No worries Sharon. I won't make any comments about the bush, but it sounds exciting.
May 22 '12 #19

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

Similar topics

5
12197
by: 00steve | last post by:
Hi, I have a group of records that I need to sort by time field. The time field is a text string (should've been a date/time - I know -doh!) I was wondering if anyone knew how to write a query...
2
3635
by: 00steve | last post by:
Hi, I have a group of records that I need to sort by time field. The time field is a text string (should've been a date/time - I know -doh!) I was wondering if anyone knew how to write a query...
4
2090
by: grghoward | last post by:
I am receiving a series of Microsoft Word documents from web clients that they upload to my server. I need to convert them to XML to pass through to another system. I have done this through...
1
4442
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
8
2044
by: FrzzMan | last post by:
How to convert back a string that have converted to byte using System.Text.Encoding.UTF8.GetBytes() string StringData = "This is a string"; byte ConvertedString =...
3
10241
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
2
2605
by: UJ | last post by:
I have need to convert a text string (with formatting) to an image. This is so that I can resize the image to different sizes and the formatting stays exactly the same regardless of the size. I...
6
25620
by: Dennis | last post by:
Is there anything built in to vb.net that will take a plain text string and reformat it as HTML? What I mean is: o replace newlines with <BR> o replace " with &quot; o etc. I am using vb.net...
21
7462
by: Aman JIANG | last post by:
hi I need to do this (convert double to string) fast, safe and portable. Is there any way to do this ? Except the ways following: 1. C++ I/O stream, stringstream (and boost::lexical_cast) 2....
3
6736
by: DaveRook | last post by:
Hi I've had a few error messages with this I don't understand why. It works fine in a Windows Form, but now moving it to a website, it's not working. I don't have the option to count the lines as...
0
7254
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
7153
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
7373
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
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7094
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
3230
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
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
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.