Question Trouble with date formation

nway

New member
Joined
Aug 23, 2008
Messages
3
Programming Experience
Beginner
I have problem with date and time formation, I need to get from this “12.11.2005 17:15:46” to this “121105_171546”.

I have write code and its working fine but there are too many variables and there is a problem, if the date is “4.8.2005 6:23:12”, final results are bad.

Does anyone have known how to solve this?

VB.NET:
Dim sDate As String = "12.11.2005 17:15:46"

Dim var1 As String = Microsoft.VisualBasic.Left$(sDate, 2)
Dim var2 As String = Microsoft.VisualBasic.Left$(Microsoft.VisualBasic.Mid$(sDate, 4), 2)
Dim var3 As String = Microsoft.VisualBasic.Left$(Microsoft.VisualBasic.Mid$(sDate, 9), 2)
Dim var4 As String = Microsoft.VisualBasic.Left$(Microsoft.VisualBasic.Mid$(sDate, 12), 2)
Dim var5 As String = Microsoft.VisualBasic.Left$(Microsoft.VisualBasic.Mid$(sDate, 15), 2)
Dim var6 As String = Microsoft.VisualBasic.Right$(sDate, 2)

Label1.Text = var1 & var2 & var3 & "_" & var4 & var5 & var6
 
Does this code help.

Convert the string to a date format then split the day, month etc out using the methods as outlined below.

Hope this helps

VB.NET:
[SIZE=3][COLOR=#0000ff][SIZE=3][COLOR=#0000ff][SIZE=2]Dim[/SIZE][/COLOR][/SIZE][/COLOR][/SIZE] sDate [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]String[/COLOR][/COLOR] = [COLOR=#a31515][COLOR=#a31515]"12.11.2005 17:15:46"
[/COLOR][/COLOR][COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] dte [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] DateTime = [COLOR=#0000ff][COLOR=#0000ff]CDate[/COLOR][/COLOR](sDate)
[COLOR=#0000ff][COLOR=#0000ff]Dim[/COLOR][/COLOR] dteFormat [COLOR=#0000ff][COLOR=#0000ff]As[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]New[/COLOR][/COLOR] System.Text.StringBuilder()
 
[COLOR=#0000ff][COLOR=#0000ff]With[/COLOR][/COLOR] dteFormat
    .Append(dte.Day.ToString)
    .Append(dte.Month.ToString)
    .Append(dte.Year.ToString.Substring(2))
    .Append([COLOR=#a31515][COLOR=#a31515]"_"[/COLOR][/COLOR])
    .Append(dte.Hour.ToString)
    .Append(dte.Minute.ToString)
    .Append(dte.Second.ToString)
[COLOR=#0000ff][COLOR=#0000ff]End[/COLOR][/COLOR] [COLOR=#0000ff][COLOR=#0000ff]With
[/COLOR][/COLOR][COLOR=black]Label1.Text[/COLOR] = dteFormat.ToString()

Regards

ScottyB
 
Just a variation from Scotty's Code:

VB.NET:
    Public Function SpecialDate(ByVal Mydate As String) As String
        Dim _Date As Date = CDate(Mydate)
        With _Date
            Return String.Format("{0}{1}{2}_{3}{4}{5}", _
                .Day.ToString("00"), .Month.ToString("00"), .Year.ToString.Substring(2), _
                .Hour.ToString("00"), .Minute.ToString("00"), .Second.ToString("00"))
        End With
    End Function
 
Guys, you are too good to me! Thx

I have one more question, how can i get to the 'Date Picture Taken' metadata found in the JPG file?
 
Last edited:
Back
Top