Friday, July 8, 2011

Changing Date Format:

if you have date in below Mention Format :

24/12/11
21/1/11
30/9/11

and you want to Convert it on Regular Date format, You can use below mention Function For the Same

=Redate()



Function Redate(dat As String, div As String)
 ' Defining variables
   Dim da As String
   
    Dim mo As String
   
    Dim fst As String
       
        Dim chr As String
       
        Dim pos As Integer
   
        Dim leng As Integer
       
        Dim ch As String
leng = Len(dat)
For pos = 1 To leng
ch = Mid(dat, pos, 1)
If ch = div Then
fst = pos
pos = leng
Else
pos = pos + 0
End If
Next pos
Dim ch2 As String
Dim Sc As Integer
Dim pos2 As Integer
For pos2 = 1 To leng
ch2 = Mid(dat, pos2, 1)
If ch2 = div Then
Sc = pos2
End If
Next pos2
chr = (Sc - 1) - (fst)
mo = Mid(dat, fst + 1, chr)
Dim y As String
da = Left(dat, fst - 1)
y = Mid(dat, Sc + 1, leng - Sc)
If dat = "" Then
Redate = " "
Else
Redate = mo & "/" & da & "/" & y
End If
End Function

No comments: