Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default Date formatting from text

I have a rather large spreadsheet where someone has input the date as text
eg. 12th January 2004, and 2nd April 2001.

Is there a simple way that I can get this into a numerical format ie
12/01/2004 so can easily use it to calculate time periods along with other
date I have?

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default Date formatting from text

One way:

=--SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"st",""),"nd", ""),"th","")

Format as a date.

In-place:

Do three Edit/Replaces (i.e., replace st, nd and th with nothing).

In article ,
morlo wrote:

I have a rather large spreadsheet where someone has input the date as text
eg. 12th January 2004, and 2nd April 2001.

Is there a simple way that I can get this into a numerical format ie
12/01/2004 so can easily use it to calculate time periods along with other
date I have?

Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,651
Default Date formatting from text

There may be simpler ways, but one option (to get rid of the "th" and "nd",
and thus convert to something Excel will read as a date) is
=--(LEFT(A1,FIND(" ",A1)-3)&RIGHT(A1,LEN(A1)-FIND(" ",A1)))
--
David Biddulph

"morlo" wrote in message
...
I have a rather large spreadsheet where someone has input the date as text
eg. 12th January 2004, and 2nd April 2001.

Is there a simple way that I can get this into a numerical format ie
12/01/2004 so can easily use it to calculate time periods along with other
date I have?

Thanks!



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default Date formatting from text

works a treat - thanks!

"JE McGimpsey" wrote:

One way:

=--SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"st",""),"nd", ""),"th","")

Format as a date.

In-place:

Do three Edit/Replaces (i.e., replace st, nd and th with nothing).

In article ,
morlo wrote:

I have a rather large spreadsheet where someone has input the date as text
eg. 12th January 2004, and 2nd April 2001.

Is there a simple way that I can get this into a numerical format ie
12/01/2004 so can easily use it to calculate time periods along with other
date I have?

Thanks!


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default Date formatting from text

Forgot to add "rd", but you probably caught it...

In article ,
morlo wrote:

works a treat - thanks!

"JE McGimpsey" wrote:

One way:

=--SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"st",""),"nd", ""),"th","")



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default Date formatting from text

On Mon, 22 Oct 2007 06:51:03 -0700, morlo
wrote:

I have a rather large spreadsheet where someone has input the date as text
eg. 12th January 2004, and 2nd April 2001.

Is there a simple way that I can get this into a numerical format ie
12/01/2004 so can easily use it to calculate time periods along with other
date I have?

Thanks!


You can use this UDF. If the target is already a proper date, it won't change
it, but if it isn't it will make the change. You will have to format the cell
with the function as a date, or else it will appear as a serial number (e.g. 12
jan 2004 = 37998)

If the contents cannot be converted into a date, you will get a VALUE error.

You can enter the formula as:

=reDate(cell_ref)

To enter the UDF, <alt-F11 opens the VBEditor.

Ensure your project is highlighted in the project explorer window, then
Insert/Module and paste the code below into the window that opens:

==========================================
Option Explicit
Function reDate(str) As Date
Dim re As Object
Dim ResultString As String
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "(\d+)[A-Za-z]{2}"
ResultString = re.Replace(str, "$1")
reDate = DateValue(ResultString)
End Function
===============================
--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
conditional formatting for cell date to equal today's date Sistereinstein Excel Worksheet Functions 2 September 10th 12 07:53 PM
how do i convert text to date (mm/yy text to mm/dd/yyyy date)? lindsey Excel Discussion (Misc queries) 1 July 27th 07 10:05 PM
Formula Text String: Formatting Text and Numbers? dj479794 Excel Discussion (Misc queries) 5 June 30th 07 12:19 AM
Text & Date Formatting Slashman Excel Worksheet Functions 4 October 5th 06 09:16 PM
Formatting text and date together Brisbane Rob Excel Discussion (Misc queries) 2 December 10th 05 10:00 AM


All times are GMT +1. The time now is 05:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"