How to convert date to string value?
Hi expert,
I have a data field (birthdate) contains a datetime datatype (mm/dd/yyyy), how can I convert to mmdd??
say, the birthday is 8/1/1979 and convert to mmdd
DOB = DS.Tables("AcctInfoTble").Rows(3)("BRTHDATE")
strResult.Insert(12, DOB.PadLeft(37, " "))
---------------------------------------------------------------------------------------------------
Public Function GenerateA(ByRef strEmpID As String)
Dim strResult As New System.Text.StringBuilder
Dim GPConnection As SqlConnection
Dim dr As SqlDataReader
Dim GPDataset As New DataSet
GPConnection = New SqlConnection(".............................................")
Dim GPDataAdapter As New SqlDataAdapter("SELECT LASTNAME,FRSTNAME,BRTHDATE FROM UPR00102 where EmployID=' " + strEmpID + "'", GPConnection)
Dim EfundAcct As String
Dim LName as string
Dim FName as string
Dim DOB as string
GPConnection.Open()
GPDataAdapter.Fill(GPDataset, "AcctInfoTble")
Dim DS As DataSet = New DataSet
LName = DS.Tables("AcctInfoTble").Rows(1).Item("LASTNAME")
FName = DS.Tables("AcctInfoTble").Rows(2)("LASTNAME")
DOB = DS.Tables("AcctInfoTble").Rows(3)("BRTHDATE")
....................
'Position 13 16N First Name
strResult.Insert(12, FName.PadLeft(16, " "))
....................
'Position 37 4A Birthdate
strResult.Insert(12, DOB.PadLeft(37, " "))
GPConnection.Dispose()
Return strResult.ToString
End Function
Re: How to convert date to string value?
Hi,
You can use the Format command to do this
Save it from your database as a date
Dim DOB as Date
DOB = ....
Dim newDOB as string
newDOB = Format (DOB,"mmdd")
For more formatting options look up the Format function under help index
Mike
Re: How to convert date to string value?
You can also use the native .NET function of the date object called ToString and pass in a format:
Code:
Dim d As Date = #7/13/2004#
MsgBox(d.ToString("MMdd"))
Case matters in the format string so notice that the Ms are capitalized.