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!!
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
CDate should handle any of the formats you've mentioned. Try it out on a test query and see how it looks. -
SELECT DateField, CDate(DateField) FROM TableName
-
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 ??????
Can you attach a file with the data so I can look at it.
Mary
Here it is. I exported it to a dbf. Some of the values are formated mm/dd/yyyy some are mmddyyyy.
One more time....It's a zip file containing a DBF
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?
Just put them in a *.txt or *.csv file. It's a lot easier to deal with.
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)>
Thanks Linq, your advice was right on!
Glad we could help!
Linq ;0)> Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
by: vunet.us |
last post by:
How can I convert UTC time such as 1173451235415 to a local time I can
read? Thank you
|
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...
|
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
...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
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...
| |