Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 30th, 2009, 02:20 PM
gal66stang gal66stang is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 10 gal66stang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 20 m 40 sec
Reputation Power: 0
Cdate() -->Converting text to date and time

Hello,
First sorry I put this question originally as a response to a similar question and got spanked - now I know better!

I have a large text file that I receive regularly from our CAD server. There are four date/time fields that have to go to text when coming in to access. I have set up a temporary import table and then have a query where I am trying to convert the text date time to a real date time field and then will append it to the actual data table for analysis. The text field [Response_Date] looks like this:

20090301 00:00:32.000

I have added a column next to it and in the Field row of my new column used CDate([Response_Date]). When I run the query I get #Error in the new column.

Any suggestions, help or advice would be greatly appreciated!

Thanks,
Gal

PS - I have also tried:
Cdate(left([Response_Date], 5,2) & "/" &
Mid([Response_Date], 7,2) & "/" &
Mid([Response_Date], 1,4) & " " &
Mid([Response_Date], 10))

But I get the following error:
"The expression you entered contains invalid sytax...."

Reply With Quote
  #2  
Old June 30th, 2009, 03:27 PM
rpeare rpeare is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jan 2008
Posts: 1,093 rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 23 h 52 m 46 sec
Reputation Power: 227
Code:
Cdate(left([Response_Date], 5,2) & "/" & Mid([Response_Date], 7,2) & "/" & Mid([Response_Date], 1,4) )


The last part of your equation you don't need if you are calculating days only. the 00:00:32.000 part of your string is the hours, minutes and seconds which doesn't appear to matter for your purposes.
__________________
----------------
If we've helped you and you have solved your problem please post that it's been resolved so we know! The suspense kills me!

Reply With Quote
  #3  
Old June 30th, 2009, 03:37 PM
gal66stang gal66stang is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 10 gal66stang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 20 m 40 sec
Reputation Power: 0
Quote:
Originally Posted by rpeare
Code:
Cdate(left([Response_Date], 5,2) & "/" & Mid([Response_Date], 7,2) & "/" & Mid([Response_Date], 1,4) )


The last part of your equation you don't need if you are calculating days only. the 00:00:32.000 part of your string is the hours, minutes and seconds which doesn't appear to matter for your purposes.


Thanks for the response Repeare!

Actually, I do use the time also. I will manage how long it takes from response to arriving at the scene and the how long the call took, so I use all of the field.

However, even just using the date portion as suggested, I still get "The expression you entered contains invalid syntax. You omitted an operand or operator, you entered an invalid character or comma, or you entered text without surrounding it in quotation marks."

Perhaps I have been starring at this for far too long...but I just can't seem to get this worked out.

Do you have any other suggestions? THANK YOU very much for your help!!

Reply With Quote
  #4  
Old June 30th, 2009, 03:45 PM
rpeare rpeare is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jan 2008
Posts: 1,093 rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 23 h 52 m 46 sec
Reputation Power: 227
Code:
CDate(Mid([responsedate],5,2) & "/" & Mid([responsedate],7,2) & "/" & Left([responsedate],4))


This works for me, I just changed the mid(1,4) statement to the left(4) statement.

Do you have any leading spaces in your field name? that will screw things up. What I would do is check your code before trying to do the cdate function

just build the query so that it says

Code:
Mid([responsedate],5,2) & "/" & Mid([responsedate],7,2) & "/" & Left([responsedate],4)


and see what it gives you. If it's giving you something that is correctly building a string date then you can use the cdate function. I suspect you have leading spaces or some such. You will probably also have to convert the hours, minutes, seconds too I've never dealt with that portion of the date except in the long format like:

12/31/2008 12:34:00 PM

but let's solve the date part first.

Reply With Quote
  #5  
Old June 30th, 2009, 03:53 PM
gal66stang gal66stang is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 10 gal66stang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 20 m 40 sec
Reputation Power: 0
Quote:
Originally Posted by rpeare
Code:
CDate(Mid([responsedate],5,2) & "/" & Mid([responsedate],7,2) & "/" & Left([responsedate],4))


This works for me, I just changed the mid(1,4) statement to the left(4) statement.

Do you have any leading spaces in your field name? that will screw things up. What I would do is check your code before trying to do the cdate function

just build the query so that it says

Code:
Mid([responsedate],5,2) & "/" & Mid([responsedate],7,2) & "/" & Left([responsedate],4)


and see what it gives you. If it's giving you something that is correctly building a string date then you can use the cdate function. I suspect you have leading spaces or some such. You will probably also have to convert the hours, minutes, seconds too I've never dealt with that portion of the date except in the long format like:

12/31/2008 12:34:00 PM

but let's solve the date part first.


Thank you again!
Still same problem/error message. I have renamed the field on both the table and query to ResponseDate (removed the underscore between them) It is formatted as text in the table that the query is using. 20090301 00:00:32.000 it looks just like that...I can not see and leading spaces in the field name or data in the field.

Reply With Quote
  #6  
Old June 30th, 2009, 03:59 PM
rpeare rpeare is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jan 2008
Posts: 1,093 rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 23 h 52 m 46 sec
Reputation Power: 227
Did you try what I said and remove the cdate expression from your query.

Make a basic query using the table with the date field in it (it doesn't matter what you call it) add only the date field then in a second column put in mid(<date field name>,5,2) and see what it gives you, if it gives you the month portion of your expected date then go from there, if it's giving you something unexpected you may have to trim the field.

For instance if you SEE in your field:

20090301 00:00:32:000

and your expression ( mid(<date field name>,5,2) ) gives you '30' you know your formula is off.

then you could try something like

mid(trim(<date field name>),5,2) to see if it's a problem with leading spaces.

Forget trying to use the cdate function until you figure out if it's building the string correctly.

Reply With Quote
  #7  
Old June 30th, 2009, 04:09 PM
gal66stang gal66stang is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 10 gal66stang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 20 m 40 sec
Reputation Power: 0
Quote:
Originally Posted by rpeare
Did you try what I said and remove the cdate expression from your query.

Make a basic query using the table with the date field in it (it doesn't matter what you call it) add only the date field then in a second column put in mid(<date field name>,5,2) and see what it gives you, if it gives you the month portion of your expected date then go from there, if it's giving you something unexpected you may have to trim the field.

For instance if you SEE in your field:

20090301 00:00:32:000

and your expression ( mid(<date field name>,5,2) ) gives you '30' you know your formula is off.

then you could try something like

mid(trim(<date field name>),5,2) to see if it's a problem with leading spaces.

Forget trying to use the cdate function until you figure out if it's building the string correctly.



Not using Cdate and in a brand new query with only [ResponseDate] and the string you provided I still get the invalid sytax error.

Reply With Quote
  #8  
Old June 30th, 2009, 04:11 PM
gal66stang gal66stang is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 10 gal66stang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 20 m 40 sec
Reputation Power: 0
Also tried....

Mid(trim([ResponseDate],5,2)

Invalid Sytax.....

Reply With Quote
  #9  
Old June 30th, 2009, 04:14 PM
rpeare rpeare is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jan 2008
Posts: 1,093 rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 23 h 52 m 46 sec
Reputation Power: 227
This is my test db. See if it runs on your machine.
Attached Files
File Type: zip Gal66stang.zip (13.0 KB, 10 views)

Reply With Quote
  #10  
Old June 30th, 2009, 04:15 PM
rpeare rpeare is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jan 2008
Posts: 1,093 rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 23 h 52 m 46 sec
Reputation Power: 227
Mid(trim([ResponseDate],5,2)

This will give you invalid syntax you have to have () around the responsedate so it would be

mid(trim([responsedate]),5,2)

Reply With Quote
  #11  
Old June 30th, 2009, 04:22 PM
gal66stang gal66stang is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 10 gal66stang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 20 m 40 sec
Reputation Power: 0
Quote:
Originally Posted by rpeare
This is my test db. See if it runs on your machine.


It works just fine. I just don't understand! This is crazy!!

Reply With Quote
  #12  
Old June 30th, 2009, 04:24 PM
gal66stang gal66stang is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 10 gal66stang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 20 m 40 sec
Reputation Power: 0
Quote:
Originally Posted by rpeare
Mid(trim([ResponseDate],5,2)

This will give you invalid syntax you have to have () around the responsedate so it would be

mid(trim([responsedate]),5,2)


Still invalid sytax

Reply With Quote
  #13  
Old June 30th, 2009, 04:39 PM
rpeare rpeare is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jan 2008
Posts: 1,093 rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 23 h 52 m 46 sec
Reputation Power: 227
I sent you a PM with one of my email addresses. Send me a copy of your db and I'll post it for you.

Reply With Quote
  #14  
Old June 30th, 2009, 11:07 PM
rpeare rpeare is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jan 2008
Posts: 1,093 rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level)rpeare User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 23 h 52 m 46 sec
Reputation Power: 227
Your current Expr1 says:

Expr1: cdate([responsedate])

I changed it to

Expr1: CDate(Mid([ResponseDate],5,2) & "/" & Mid([responsedate],7,2) & "/" & Left([responsedate],4))

and it works just fine.
Attached Files
File Type: zip testtexttodate.zip (21.5 KB, 9 views)

Reply With Quote
  #15  
Old July 1st, 2009, 12:30 PM
gal66stang gal66stang is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 10 gal66stang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 20 m 40 sec
Reputation Power: 0
Quote:
Originally Posted by rpeare
Your current Expr1 says:

Expr1: cdate([responsedate])

I changed it to

Expr1: CDate(Mid([ResponseDate],5,2) & "/" & Mid([responsedate],7,2) & "/" & Left([responsedate],4))

and it works just fine.


Apparently I need to quit bleaching my hair-it is starting to seep in to the brain cells! THANK YOU so much for spending time on this with me. It works great!

Take care...gal...

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > Cdate() -->Converting text to date and time


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
Stay green...Green IT