My Assistant
![]() ![]() |
|
|
Jun 11 2009, 02:54 PM
Post
#1
|
|
|
New Member Posts: 6 |
Hi,
I'm trying to get around an issue I'm having with a set of data that has a [Date] in a text string format (See below): 14th January 2009 (17 characters in length) 7th March 2009 (15 characters in length) 2nd September 2009 (19 characters in length) Ideally I want the above to appear in the following format as a date value: 14/01/2009 7/03/2009 2/09/2009 The source data is from an Excel spreadsheet that is emailed to me weekly. I don't want to perform the conversion within Excel as my aim is to just to link the spreadsheet into the database and append the updated weekly data into a table for further manipulation. If it is not possible to perform a conversion then could someone tell me how I select just the month from the above from the string (14th January 2009). If I could do this I could create a simple lookup table: Month Month No January 1 February 2 March 3 etc... Then Bring the three elements together as I already know how to separate the [DD] and [YYYY]: Application Date:([DD]&"/"&[MM]&"/"&[YYYY]) Hope that makes sense and that there is a simple solution. Thanks in Advance Steve |
|
|
|
Jun 11 2009, 03:21 PM
Post
#2
|
|
|
Access Wiki and Forums Moderator Posts: 48,021 From: SoCal, USA |
Hi Steve,
Welcome to Utter Access! To get the month, you could try something like: Split([FieldName], " ")(1) or something like: Dim MyData() As String Dim MyMonth As String MyData = Split([FieldName], " ") MyMonth = MyDate(1) (untested) Hope that helps... |
|
|
|
Jun 11 2009, 03:34 PM
Post
#3
|
|
|
New Member Posts: 6 |
It isnt working for me unfortunately? Thanks for the suggestion.
|
|
|
|
Jun 11 2009, 03:43 PM
Post
#4
|
|
|
Utterly Banned Posts: 7,038 |
Put this into a standard module (do not name the module the same as the function):
CODE Public Function ConvertToDate(strDateString As String) As Date
Dim varSplit As Variant varSplit = Split(strDateString, " ") ConvertToDate = DateSerial(varSplit(2), varSplit(1), varSplit(0)) End Function then you just use it in your query like: MyNewFieldNameHere:ConvertToDate([YourOldFieldNameHere]) |
|
|
|
Jun 11 2009, 03:52 PM
Post
#5
|
|
|
New Member Posts: 6 |
I just copy to code into the module as it is no amendments? I adjusted the query part:
Month: ConvertToDate([Date]) I have done this and get an error message of type mismatch and the code stops at: ConvertToDate = DateSerial(varSplit(2), varSplit(1), varSplit(0)) Sorry for the stupid questions but i really appreciate the support. |
|
|
|
Jun 11 2009, 04:44 PM
Post
#6
|
|
|
Utterly Banned Posts: 7,038 |
You may have null values.
Also, you should NOT have a field named DATE as that is an Access Reserved Word. You should change that ASAP. Also MONTH is a reserved word. You may need to use: NewDate: ConvertToDate(Nz([Date])) |
|
|
|
Jun 11 2009, 04:53 PM
Post
#7
|
|
|
New Member Posts: 6 |
There are no nulls and its still not working. Nightmare!!
|
|
|
|
Jun 12 2009, 12:11 AM
Post
#8
|
|
|
UtterAccess Addict Posts: 199 From: Western Australia |
Try this,
I took Bob's mod and modified;- Works for dates supplied. Cheers Darren
Attached File(s)
|
|
|
|
Jun 12 2009, 07:05 AM
Post
#9
|
|
|
Retired Moderator Posts: 13,544 From: Texas (Is there anywhere else?) |
Modify Bobs code to remove the ordinal text and change the DateSerial() to CDate().
CODE Public Function ConvertToDate(strDateString As String) As Date
Dim varSplit As Variant varSplit = Split(strDateString, " ") varSplit(0) = Val(varSplit(0)) ConvertToDate = CDate(Join(varSplit, " ")) End Function |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 22nd May 2013 - 11:49 PM |