Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Is the string a date?

I'm writing a macro in VBA
In it, I'm reading part of a long string and I want to know if that
part is a date or not. Is there a way to do that?

Thank you

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 182
Default Is the string a date?

Hi,

It is possible if you post your string you want to get the date there...
so someoneelse will helps you...

--

Regards,

Halim


" wrote:

I'm writing a macro in VBA
In it, I'm reading part of a long string and I want to know if that
part is a date or not. Is there a way to do that?

Thank you


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Is the string a date?

The string can be anything. That's the reason why I didn't post
anything.
The string can be an actual date like 12252006 but it can also be
abcde05
I'm looking for a test to figure out if the string is a date or not a
date

Halim wrote:
Hi,

It is possible if you post your string you want to get the date there...
so someoneelse will helps you...

--

Regards,

Halim


" wrote:

I'm writing a macro in VBA
In it, I'm reading part of a long string and I want to know if that
part is a date or not. Is there a way to do that?

Thank you



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Is the string a date?

If your string is always 8 characters, you could use code like

Dim D As Date
Dim S As String
S = "asdd2006"
On Error Resume Next
Err.Clear
D = DateSerial(Right(S, 4), Left(S, 2), Mid(S, 3, 2))
If Err.Number < 0 Then
Debug.Print "Not a date"
Else
Debug.Print "Date: " & D
End If

If the length of the string varies, you'd have to write a bunch of Left,
Mid, and Right function to break the string into multiple elements, pass
those elements to DateSerial, and test the error.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)



wrote in message
ups.com...
The string can be anything. That's the reason why I didn't post
anything.
The string can be an actual date like 12252006 but it can also be
abcde05
I'm looking for a test to figure out if the string is a date or not a
date

Halim wrote:
Hi,

It is possible if you post your string you want to get the date there...
so someoneelse will helps you...

--

Regards,

Halim


" wrote:

I'm writing a macro in VBA
In it, I'm reading part of a long string and I want to know if that
part is a date or not. Is there a way to do that?

Thank you





  #5   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Is the string a date?

This seemed to work okay.

S = Format("12252006", "##/##/####")
If IsDate(S) Then D = CDate(S)



"Chip Pearson" wrote:

If your string is always 8 characters, you could use code like

Dim D As Date
Dim S As String
S = "asdd2006"
On Error Resume Next
Err.Clear
D = DateSerial(Right(S, 4), Left(S, 2), Mid(S, 3, 2))
If Err.Number < 0 Then
Debug.Print "Not a date"
Else
Debug.Print "Date: " & D
End If

If the length of the string varies, you'd have to write a bunch of Left,
Mid, and Right function to break the string into multiple elements, pass
those elements to DateSerial, and test the error.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)



wrote in message
ups.com...
The string can be anything. That's the reason why I didn't post
anything.
The string can be an actual date like 12252006 but it can also be
abcde05
I'm looking for a test to figure out if the string is a date or not a
date

Halim wrote:
Hi,

It is possible if you post your string you want to get the date there...
so someoneelse will helps you...

--

Regards,

Halim


" wrote:

I'm writing a macro in VBA
In it, I'm reading part of a long string and I want to know if that
part is a date or not. Is there a way to do that?

Thank you






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
Convert Date string to date format Joe M. Excel Discussion (Misc queries) 7 May 6th 10 02:46 PM
Date String Jester Excel Discussion (Misc queries) 1 February 28th 07 10:00 AM
changing a string date into a 'date' DowningDevelopments Excel Programming 4 December 9th 05 05:00 PM
Date and string help andycharger[_5_] Excel Programming 3 January 19th 04 06:36 PM
Converting a string date into a Excel Date Phillips Excel Programming 0 November 24th 03 08:54 PM


All times are GMT +1. The time now is 04:07 AM.

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

About Us

"It's about Microsoft Excel"