Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Parse a date

Trying to parse a date to save appended to filename with spaces, don't want /.

So I use instr to locate the position of the first / so I can parse the day
and month.
How do I use instr to locate the second / in the date?
TIA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Parse a date

Hi Headley,

Will this example help? Reset the format in the double quotes to your date
format.
Look up 'Replace function' in help for more info.

Sub Test_Instr()

Dim testDate As Date
Dim testString

testDate = #2/4/2007# 'Actual date

'Replaces all occurrences of /
testString = Replace(Format(testDate, "dd/mm/yyyy"), "/", "")

End Sub


"headly" wrote:

Trying to parse a date to save appended to filename with spaces, don't want /.

So I use instr to locate the position of the first / so I can parse the day
and month.
How do I use instr to locate the second / in the date?
TIA

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Parse a date

Should have said removes all occurrences of /
If you want to relace all occurrences of / with another character
then put that character within the last double quotes. Space is valid.

Also you don't need to use replace function. Simply use the following:-

testString = Format(testDate, "dd mm yyyy")

You can choose any format you like. "yyyy mm dd" is valid and will
make your files sort in proper date order.

Regards,

OssieMac

"headly" wrote:

Trying to parse a date to save appended to filename with spaces, don't want /.

So I use instr to locate the position of the first / so I can parse the day
and month.
How do I use instr to locate the second / in the date?
TIA

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Parse a date

shi
are you doing this with formula or macro? I have never heard of instr. but
since you used the word parce....
I took today's date and did a text to column using delimited parse, other =
/ and it parsed the date numbers into 3 cells omitting the /. I then used
this formula...
=C6&D6&E6 to achieve the results 7222007.
i used this formula =C6&D6&RIGHT(E6,2) to achieve the results 72207.
macro...
Sub rename()
Dim nam1 As String
Dim nam2 As String
Dim nam3 As String
Dim sd As Date

sd = InputBox("Enter the date")
nam1 = Day(sd)
nam2 = Month(sd)
nam3 = Year(sd)

ActiveWorkbook.SaveAs Filename:= _
"C:\yourpath\filename" & nam2 & " " & nam1 & " " & nam3 & ".xls" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
end sub

regards
FSt1

trying to parse a date to save appended to filename with spaces, don't want /.

So I use instr to locate the position of the first / so I can parse the day
and month.
How do I use instr to locate the second / in the date?
TIA

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
How to parse a string with a date? [email protected] Excel Worksheet Functions 1 June 13th 06 07:46 AM
How do i parse a text string with a date? [email protected] Excel Programming 1 June 13th 06 07:02 AM
Parse from the Right PA Excel Worksheet Functions 6 June 11th 06 06:05 PM
Please help me Parse this sjones Excel Programming 2 April 5th 04 12:15 AM
Parse Sarah[_4_] Excel Programming 2 December 30th 03 11:16 PM


All times are GMT +1. The time now is 07:04 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"