convert a text date to a true date

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am out of ideas. Excelâ„¢ XP on WinnXP.
I have acquired a spreadsheet "database" from another user. approximayely 5K
records with dates in the dddd, m-d-yy format, although these appear to be
stored as text. Changing the format does not change theway data is displayed.
Cells were originally formatted as General.

Can anyone offer a simple formula method to change these text entries into a
true date format? I am in process of importing info into an Accessâ„¢ database.

Thanks for any suggestions
 
I have a situation where my dates come to me as 1071114 (107 is the year, 11,
is the month and 14 is the day). I use the formula
=date(left(a1,3),mid(a1,4,2),right(a1,2)) and it converts to 11/14/2007. May
take a bit of modification but it should work for you.

Luck
 
Thanks Tom for that. MAybe I should be a bit more specific.
My dates are text such as
Sunday, March 3, 2002
Wednesday, April 11, 2004
Friday, December 20, 2003
and so forth.
 
If these are indeed TEXT entries you can use Text to Columns to convert
them. You'll lose the dddd portion but retain the date portion.

Select the range of cells in question
Goto the menu Data>Text to Columns
Select Delimited>Next>select both Comma and Space>Next
In Step 3 the first partition should be highlighted in the data preview box.
Select Do not import
Finish
 
Assuming your first date is in A2, put this formula in the 2nd row of a help
column...

=DATE(RIGHT(A2,2),MID(A2,FIND("-",A2)-2,2),MID(A2,FIND("-",A2)+1,LEN(A2)-3-FIND("-",A2)))

and copy it down through all the rows that have dates in them. Then select
all the dates in this helper column and Edit/Copy (or Ctrl+C) them; then
select A2 (the first cell containing the original date) and click
Edit/PasteSpecial in Excel's menu bar; select Values from the option list
and hit OK; then delete the helper column and format the newly copied dates
however you want them to look.

Rick
 
I am out of ideas. Excel™ XP on WinnXP.
I have acquired a spreadsheet "database" from another user. approximayely 5K
records with dates in the dddd, m-d-yy format, although these appear to be
stored as text. Changing the format does not change theway data is displayed.
Cells were originally formatted as General.

Can anyone offer a simple formula method to change these text entries into a
true date format? I am in process of importing info into an Access™ database.

Thanks for any suggestions


=--MID(A1,FIND(",",A1)+2,255)

Format as date
--ron
 
Given the different date format that you just posted in JR Hester's
subthread, use this formula in the help column using the procedure I
outlined instead of the formula I originally posted...

=--SUBSTITUTE(A2,LEFT(A2,FIND(" ",A2)),"")

Rick
 
Rick,

this doesn't work in the UK, as

March 3, 2002

is not a valid date string. I'll post my solution direct to the OP.

Pete
 
Assuming the date text is in I11:

=DATEVALUE(RIGHT(I11,LEN(I11)-FIND("^^",SUBSTITUTE(I11,",","^^",
1))-1))

Will work for all three examples cited, as well as others I can think
of. The requirement is that the weekday name be followed by a comma,
and the rest of the string an Excel-recognized date display. For
instance, these will all work:

Monday, 3/3/02
Monday, Aug 10 (assumes current year)
randomtext, Aug-12 (assumes current year)
randomtext, Aug 12, 2005

Will work also for differing regional setting, assuming the weekday
followed by comma requirement is met.
 
You may have seen debates here in the past about using DATE and
DATEVALUE - the problem with the latter (taking strings) is the
regional variations in strings that are recognised as dates in
different countries, so solutions may not work universally. Bearing
this in mind, I would propose the following:

First of all, set up a table of months and the month number, like
this:

Jan 1
Feb 2
Mar 3
Apr 4
May 5
Jun 6
Jul 7
Aug 8
Sep 9
Oct 10
Nov 11
Dec 12

It doesn't really matter where this is (I put mine in M4:N15), but you
should give the table a name like "months" by highlighting the data
and Insert | Name | Define. Then, if your text date is in K4 in the
format you spelled out in your second post, you can use this formula
to convert it to a proper date:

=DATE(RIGHT(K4,4),VLOOKUP(MID(K4,FIND(",",K4)+2,3),months,
2,0),MID(K4,LEN(K4)-7,2))

Obviously, adjust the references to K4 to suit your first cell.

Format the cell appropriately, and then copy down if you have other
dates in column K.

The formula should work whichever country you are in.

Hope this helps.

Pete
 
this doesn't work in the UK, as
March 3, 2002

is not a valid date string. I'll post my solution direct to the OP.

Really? I have no experience with international units, but I figured the
Excel date engine would work the same as the VB/VBA date engine... if the
date engine could interpret something as a date in **any** possible way,
then that is how it interprets it. I'm guessing, based on your posting, that
for the Excel spreadsheet world, this is not the case. Thanks for letting me
know.

Rick
 
I only discovered this a couple of days ago when a poster from the US
sent me a file to look at and all his dates came up as #VALUE, so I
had to change his formulae from DATEVALUE to DATE before I could look
into the problem he had asked me to look at - so, it was fresh in my
mind!!

We normally enter dates here as day first followed by month and then
year, so 3 March or 3 March 2007 are recognised, but March 3 2007 or
March 3, 2007 are not, and are treated as strings.

So, you learn something new every day <bg>

Pete
 
We normally enter dates here as day first followed by month and then
year, so 3 March or 3 March 2007 are recognised, but March 3 2007 or
March 3, 2007 are not, and are treated as strings.

I knew you guys wrote your dates backwards<g>, but VB/VBA will still
interpret them as dates here. Likewise, if you go into the VBA editor and
type/enter this...

Print IsDate("March 3, 2007")

in the Immediate window, it will print True just like if I type/enter
this...

Print IsDate("3 March 2007")

here, it too will print True. VB/VBA will accept anything that is considered
a date anywhere in the world as a date in any locale (within Date functions,
of course). I just figured the same date engine was at work within the Excel
spreadsheet world as well.
So, you learn something new every day <bg>

Yep... I did with this thread. Thanks again for pointing it out to me.

Rick
 
Yes, I can confirm that

Print IsDate("March 3, 2007")

in the Immediate window does produce True, so obviously there is a
difference between the way VBA and spreadsheet functions handle dates.

Pete
 
Rick,

this doesn't work in the UK, as

March 3, 2002

is not a valid date string. I'll post my solution direct to the OP.

Pete

Thanks for pointing that out, Pete. I just confirmed it here by changing my
Regional settings to UK.
--ron
 
Nothing like consistency within the same product, eh?

Thanks for the confirmation on that.

Rick
 
March 3 2007 (or Mar 3 2007) is not a valid date string in the U.S., either!
U.S. regional format - m/d/yyyy

DATEVALUE = #VALUE!

However, these are valid:

Mar 3, 2007
March 3, 2007

It seems the comma makes all the difference!
 
March 3 2007 (or Mar 3 2007) is not a valid date string in the U.S., either!
U.S. regional format - m/d/yyyy

DATEVALUE = #VALUE!

However, these are valid:

Mar 3, 2007
March 3, 2007

It seems the comma makes all the difference!

The comma does NOT make a difference if your regional settings are
English(United Kingdom). Still get the #VALUE! error
--ron
 
The OP specified the format (with the comma) in the second response (to JR
Hester) which is what I posted my

=--SUBSTITUTE(A2,LEFT(A2,FIND(" ",A2)),"")

formula against. Pete's first reply specifically said in his first reply to
me that..

"this doesn't work in the UK, as

March 3, 2002

is not a valid date string"

Note the comma in his message. Are you now saying that my SUBSTITUTE formula
above does, in fact, work in locales other than the US (provided the comma
is present)?

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top