convert date format

Chinavo

Member
Joined
Jul 16, 2008
Messages
16
Programming Experience
1-3
Hi again

i read a date out of a listview (as a string).
Now i want to save that date to a sql express database.

As u might now the required form of the date by sql is:

mm/dd/yyyy

But i get the date in the format

dd/mm/yyyy

what is the easiest way to convert the given string to the required
sting??

thx for the help!

chinavo
 
Thread moved

VB.NET:
        Dim SelDate As String = "18/07/2008" ' July 18th 2008
        Dim DatePieces() As String = SelDate.Split("/"c)
        Dim dt As New DateTime(CInt(DatePieces(2)), CInt(DatePieces(1)), CInt(DatePieces(0)))
        SelDate = dt.ToShortDateString 'SelDate now equals "7/18/2008" which is still July 18th 2008
What this does is take the known source date from the string, split it into the individual numbers then assigns it to a new DateTime object then grabs the same date in the sql correct order.
 
the shortest i guess is you parse it as date and format it:

ex.
VB.NET:
ci as New CultureInfo("de-DE")
date as String= String.Format("{0:MM/dd/yyyy}",DateTime.Parse("28/7/2008",ci))


You need to make reference of the assembly System.Globalization
 
Last edited:
Converting Date Format In Visual Basic Dot Net

I am using following method to convert date format.

Dim sTodaysDate As String
sTodaysDate = Now 'Current Date Using String Varaible

' Date Conversion For String Variable
sTodaysDate = CDate(sTodaysDate).ToString("yyyyMMdd")
 
Back
Top