How to convert date to string value?-VBForums
Results 1 to 3 of 3

Thread: How to convert date to string value?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2004

    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

    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, " "))

    Return strResult.ToString
    End Function

  2. #2
    New Member
    Join Date
    Dec 2004

    Re: How to convert date to string value?


    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


  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Moreno Valley, CA (SoCal)

    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:
            Dim d As Date = #7/13/2004#
    Case matters in the format string so notice that the Ms are capitalized.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width