Date displays DateTime

richlp

Member
Joined
Oct 16, 2009
Messages
9
Programming Experience
10+
I have a GridView control on a form. There is a button which populates the grid


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim tvPage1 As TreeView = CType(Session("treeview"), TreeView)

Dim strConn As String = CType(Me.Master, MasterPage).connectString
Dim objConn As New MySqlConnection(strConn)
Dim objDS As New DataSet

Dim ldDate As String = (CType(ddlDates.SelectedValue, Date).GetDateTimeFormats())(66)

Dim strSql As String
strSql = "SELECT action,totNumberActions,Status,totCountStatus,categoryname,createdate " & _
" FROM kpi_mrpactions " & _
" WHERE savedate = '" & ldDate & "'" & _
" ORDER BY action,status "

Dim daMrp As New MySqlDataAdapter(strSql, objConn)
daMrp.Fill(objDS, "dtMrp")
GridView1.DataSource = objDS
GridView1.DataBind()

End Sub

The data is coming from a MySql table.
The < createdate > column is of type DATE (definitely not DATETIME -- I checked). But the column in the gridview is showing a Time portion (for example: 12/12/2009 12:00:00 AM).

Is there a setting somewhere that maps Dates to DateTime displays????

Is there some way to modify the display so that only the date portion shows???

Is there some way to modify the query to ensure a date value is returned and displayed as a date???

All replies greatly appreciated............Rich
 
VB.NET:
Dim temp_date As New DateTime()
            temp_date = DateTime.Now.Date
This displays a date along with the correct time.

Thanks for the reply but I believe you have mis-read the problem.

I don't want a datetime value. The problem is that I am retrieving Date values from a query but they are displaying with a time portion. I just want the date, not the time.
 
You could use

VB.NET:
FormatDateTime(Date,DateFormat.ShortDate)

Will display just the date and not the time.
 
Last edited:
You could use

VB.NET:
FormatDateTime(Date,DateFormat.ShortDate)

Will display just the date and not the time.

Thanks for replying.........

I doubt that I can put this into the MySql query. How can I incorporate your suggestion into the column of the grid which needs formatting.

........Rich
 
I believe you should be able to use something like this

VB.NET:
Me.DataGridView1.Columns("columnname").DefaultCellStyle.Format = "d"

That should show the short date.

Also, have you tried the DATE() function in MySql? For example:

VB.NET:
select DATE(datafield) from sometable
 
Back
Top