473,383 Members | 1,805 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,383 software developers and data experts.

Convert String To Date

To the Experts: I have a string field I need to convert to date format. I have the following formats:

mm/dd/yyyy
mm/d/yyyy
m/dd/yyyy
m/d/yyyy

What to do?? can I use Cdate?? if so, how to get around the different formats?

Thanks!!
Nov 10 '09 #1

✓ answered by missinglinq

The mmddyyyy data is causing the problem. In order for CDate() to work correctly the data has to look like a date.

These all look like dates:

mm/dd/yyyy
mm/d/yyyy
m/dd/yyyy
m/d/yyyy


This doesn't:

mmddyyyy

You're going to have to make these last "dates" look like dates before using CDate().

A value like 122009 could be parsed correctly and slashes placed appropriately to make it look like a date, because it has 6 characters. Assuming that the last four represent the year, it could only represent 1/2/2009.

But a value like 1292009 cannot be parsed correctly, because it could be 1/29/2009 or 12/9/2009.

I think you're going to have to do this by manually changing the mmddyyyy fields, changing the obvious values (those that could only be interpreted in one way) and using other documentation to decide which is the correct interpretation for "dates" like like 1292009 which could be 1/29/2009 or 12/9/2009, then running your query using CDate().

What I'd do is create a query to pull all of these records, change them manually, then run your CDate query against the table.

To do this, create a select query against your table with the original "date" field, and a new field with this in the name box:

IsDate([OriginalDateFieldName])

Now, in this field's Criteria box enter "0", quotes and all.

When you run this query it will return all records whose "date" field cannot be evaluated as a date, and you can manually insert the slashes in the correct positions.

After doing this you can run your query using the CDate() function.

The most important thing, of course, is to insure that the dates are entered appropriately in the future.

Linq ;0)>

10 6215
MMcCarthy
14,534 Expert Mod 8TB
CDate should handle any of the formats you've mentioned. Try it out on a test query and see how it looks.

Expand|Select|Wrap|Line Numbers
  1. SELECT DateField, CDate(DateField) FROM TableName
  2.  
Nov 10 '09 #2
I'm working in a querty window...Getting some strange results...Here is my formula: AcDate: CDate([action date]).

Most of the result fields contain this: #ERROR.

A field with this value 02/04/2009 Returns 10/29/7490 ??????
Nov 10 '09 #3
MMcCarthy
14,534 Expert Mod 8TB
Can you attach a file with the data so I can look at it.

Mary
Nov 10 '09 #4
Here it is. I exported it to a dbf. Some of the values are formated mm/dd/yyyy some are mmddyyyy.
Nov 11 '09 #5
One more time....It's a zip file containing a DBF
Attached Files
File Type: zip ACTIONS.zip (21.7 KB, 131 views)
Nov 11 '09 #6
NeoPa
32,556 Expert Mod 16PB
@dieselrocks
What is a DBF file?

How can some be mmddyyyy now when they weren't in your first post?

I think this requires more of an explanation than dropping it into some post with some other stuff.

What exactly is the problem?
Nov 11 '09 #7
MMcCarthy
14,534 Expert Mod 8TB
Just put them in a *.txt or *.csv file. It's a lot easier to deal with.
Nov 11 '09 #8
missinglinq
3,532 Expert 2GB
The mmddyyyy data is causing the problem. In order for CDate() to work correctly the data has to look like a date.

These all look like dates:

mm/dd/yyyy
mm/d/yyyy
m/dd/yyyy
m/d/yyyy


This doesn't:

mmddyyyy

You're going to have to make these last "dates" look like dates before using CDate().

A value like 122009 could be parsed correctly and slashes placed appropriately to make it look like a date, because it has 6 characters. Assuming that the last four represent the year, it could only represent 1/2/2009.

But a value like 1292009 cannot be parsed correctly, because it could be 1/29/2009 or 12/9/2009.

I think you're going to have to do this by manually changing the mmddyyyy fields, changing the obvious values (those that could only be interpreted in one way) and using other documentation to decide which is the correct interpretation for "dates" like like 1292009 which could be 1/29/2009 or 12/9/2009, then running your query using CDate().

What I'd do is create a query to pull all of these records, change them manually, then run your CDate query against the table.

To do this, create a select query against your table with the original "date" field, and a new field with this in the name box:

IsDate([OriginalDateFieldName])

Now, in this field's Criteria box enter "0", quotes and all.

When you run this query it will return all records whose "date" field cannot be evaluated as a date, and you can manually insert the slashes in the correct positions.

After doing this you can run your query using the CDate() function.

The most important thing, of course, is to insure that the dates are entered appropriately in the future.

Linq ;0)>
Nov 11 '09 #9
Thanks Linq, your advice was right on!
Nov 17 '09 #10
missinglinq
3,532 Expert 2GB
Glad we could help!

Linq ;0)>
Nov 17 '09 #11

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

Similar topics

13
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and...
2
by: Hector A | last post by:
Hi I'm trying to convert a string that already looks like a date to a date that I can use when I pass it from java to the database. I receive the date in format yyyy-mm-dd and I need it to be a...
2
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings...
12
by: DC Gringo | last post by:
How can I convert this pubLatest to a date with format "m/d/yyyy"? Dim pubLatest As New Date pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value -- _____ DC G
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
4
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that...
6
by: vunet.us | last post by:
How can I convert UTC time such as 1173451235415 to a local time I can read? Thank you
8
by: deepak_kamath_n | last post by:
Hello, I have the following scenario: 1. My application receives the date from another application as a string 2. The other application is running in a different time zone as compared to my...
4
by: Ashraf Ansari | last post by:
Hi, How Can I convert MM/dd/yyyy format into dd/MM/yyyy and the date which is converted into dd/MM/yyyy should be in DateTime format. I do not want to store it as a string. Please help ...
4
by: =?Utf-8?B?YW5kcmV3?= | last post by:
I am running an ASP.net program written in VB. At one point I try to convert a date string into a date time object... this string is from a central dev server and the code works on many other...
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
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.