Community discussion forum

how can i print dateofbirth as date instead of datetime

  • 1 year ago

    i am using a property to get dateofbirth from a textbox and i am printing the property in another class

    by using the obj.propertyname for dateofbirth but i am able to print it as only datetime only i am not getting only the date since it is hard to read it as for eg 1/1/2000 12:00AM i am getting like this

    but i want it to get as only 1/1/2000 i am also using only the datatype date i know that this will print along with datetime but i want to know whether can i make it print only the date

  • 1 year ago

    I'm not sure if you mean this, but please have a look at this code:

    Public Class Form1
    
        Private myDate As DateTime
        Private msg As String
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            myDate = Now
            msg = "Date of Today :  " & myDate.Date & ControlChars.NewLine
            msg = msg & "Time now :  " & myDate.ToLongTimeString
            MsgBox(msg)
        End Sub
    
    End Class
  • 1 year ago

    Don't use FormatDateTime.

    lblDateOfBirth.Text = dateOfBirth.ToShortDateString()

    The Date type has ToShortDateString, ToLongDateString, ToShortTimeString and ToLongTimeString methods, plus it has a ToString method that will accept any standard or custom format string.  ToShortDateString is equivalent to ToString("d").

Post a reply

Enter your message below

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!