Function to insert char into string (1 Viewer)

the_wickedman

New member
Local time
Today, 21:02
Joined
Aug 12, 2006
Messages
3
Hi,

Could somebody help me with easy (I think so) problem?:
I have date (as string) like 20060826. I need insert into 20060826 this "-" -> 2006-08-26
Regards,
Michal
 

RV

Registered User.
Local time
Today, 20:02
Joined
Feb 8, 2002
Messages
1,115
You can achieve this in multiple ways, using combinations of the Left, Mid, Right, Len and Format functions.

FYI, similar questions have been asked quite often on the forum.

Rv
 

jwhite

Software Developer
Local time
Today, 15:02
Joined
Sep 24, 2006
Messages
141
Thought it might be useful for the function to also return the current date if you need...

Option Compare Database
Option Explicit

Public Function Datefix(Optional inDate As String)
'If no date passed to function, use current date
If inDate = "" Then inDate = Format(Date, "yyyymmdd")
Datefix = Left$(inDate, 4) & "-" & Mid$(inDate, 5, 2) & "-" & Mid$(inDate, 7)
'Debug.Print Datefix
End Function
 

smithveg

New member
Local time
Today, 12:02
Joined
Feb 18, 2008
Messages
1
Since this is a date time.

You may try out by:
yourtext.substring("{#:yyyy-MM-dd}",yourstring)
 

Users who are viewing this thread

Top Bottom