Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Format

Status
Not open for further replies.

obede

Technical User
Jan 26, 2006
8
BR
Hi, dear

How can I format the string "Saturday, April 19, 2008" into "yyyyMMdd" date format?
Is it possible?

Thank you very much

Obede
Brazil
 
Thank you, jmeckley but the MSDN help doesn't show an example that convert "Saturday, April 19, 2008" into "yyyyMMdd" date format.

Does anybody know how to convert this string?

Thank you very much.
 
You may not find and EXACT example, but that article should point you in the right direction. Convert the string to a date, then format the date(in string format) the way you like.
 
Here, I wrote your code for you:
Code:
       Dim MyString As String = "Saturday, April 19, 2008"
        Dim MyFormattedString As String
        MyFormattedString = DateTime.Parse(MyString).ToString("yyyyMMdd")

        Response.Write(MyFormattedString)
 
As I don't know the string format and the format I want to get, I created a function:

Friend Function FormattedDate(ByVal sDate As String, ByVal sFormat As String) As String

' Funçao para formatar a string contendo uma data em um dos 20 formatos abaixo no formato desejado
Try
Dim sDates(19) As String
sDatas(0) = "dd/MM/yyyy"
sDatas(1) = "MM/dd/yyyy"
sDatas(2) = "yyyy/MM/dd"
sDatas(3) = "ddMMyyyy"
sDatas(4) = "MMddyyyy"
sDatas(5) = "yyyyMMdd"
sDatas(6) = "dd-MM-yyyy"
sDatas(7) = "MM-dd-yyyy"
sDatas(8) = "yyyy-MM-dd"
sDatas(9) = "dddd, dd MMMM yyyy"
sDatas(10) = "dd/MM/yy"
sDatas(11) = "MM/dd/yy"
sDatas(12) = "yy/MM/dd"
sDatas(13) = "ddMMyy"
sDatas(14) = "MMddyy"
sDatas(15) = "yyMMdd"
sDatas(16) = "dd-MM-yy"
sDatas(17) = "MM-dd-yy"
sDatas(18) = "yy-MM-dd"
sDatas(19) = "dddd, dd MMMM yy"

Return Date.ParseExact(sDate, sDates, CultureInfo.InstalledUICulture, DateTimeStyles.None).ToString(sFormat)
Catch ex As Exception
Return String.Empty
End Try

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top