Guys please help me out on ths'
I have created a table in sql ' managed to change datetime to date only in (sql query analyzer ' parsed it ) its shown date only n sql table but its shown both datetime in vb.net textbox Please tell me if my method is right or gve me the correct method.
I will be really thankful. U can even e mail me direct on my e mail
sunilgill2007@hotmail.com

Use ToShortDateString of the DateTime class. Here's an example

Dim SQLDateTime As Date
Dim OnlyDate As String

' Debug, get this value from SQL Server. Notice: This is my locale date format
SQLDateTime = CDate("15.5.2009 15:53:00")
OnlyDate = SQLDateTime.ToShortDateString

MessageBox.Show(OnlyDate, "Only Date", MessageBoxButtons.OK, MessageBoxIcon.Information)

Here's another way to do it

Dim SQLDateTime As Date
Dim OnlyDate As String
Dim TempPos As Integer

' Debug, get this value from SQL Server. Notice: This is my locale date format
SQLDateTime = CDate("21.5.2009 10:36:00")
' Locate the space character. That should be a separator between the date and the time parts
TempPos = SQLDateTime.ToString.IndexOf(" ")
If TempPos >= 0 Then
  OnlyDate = SQLDateTime.ToString.Substring(0, TempPos)
Else
  OnlyDate = "Invalid date"
End If

MessageBox.Show(OnlyDate, "Only Date", MessageBoxButtons.OK, MessageBoxIcon.Information)

If you still can't get the date part only, show the original datetime value read from DB.

This article has been dead for over six months. Start a new discussion instead.