formating date in a data grid row

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a large data grid with several rows that contain dates. I want to display the date only(no time). Even when I use the trunc function in Oracle the rows show a time of 12:00:00 am.
What I get now: 11/11/2003 12:00:00 am What I want is just the 11/11/2003. I have searched help and haven't been able to find this particular topic.

Any help will be appreciated.

Jack
 
This is actually an ASP.Net question, try to post in the ASP newsgroup, your
question will get answered quicker.

You can use the FormatDate fuction before you bind the dataset to your
datagrid

like:

Private Sub BindData()
Dim MyConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User
Id=admin;Password=;"
Dim db As New OleDb.OleDbConnection(MyConnectionString)
db.Open()
Dim cmd As New OleDb.OleDbCommand("Select * FROM MyTable")
Dim ds As New DataSet, da As New OleDb.OleDbDataAdapter(cmd, db)
da.Fill(ds)

For Each row As DataRow In ds.Tables(0).Rows
row.Item("MyColumnName") =
FormatDateTime(row.Item("MyColumnName"), DateFormat.ShortDate)
row.Item("AnotherDateColumn") =
FormatDateTime(row.Item("AnotherDateColumn"), DateFormat.ShortDate)
Next
Me.DataGrid1.DataSource = ds
Me.DataGrid1.DataBind()
End Sub

Hope that helps
Jared

Jack M said:
I have a large data grid with several rows that contain dates. I want to
display the date only(no time). Even when I use the trunc function in
Oracle the rows show a time of 12:00:00 am.
What I get now: 11/11/2003 12:00:00 am What I want is just the
11/11/2003. I have searched help and haven't been able to find this
particular topic.
 
Jack,

There's a <format> property on the datagridtextboxcolumn,
and for that format for short date you'd specify "d"
(or "D" for long date). Likewise, "C" for currency, "N"
for numeric, etc., per the standard format strings.

Here's from the on-line docs for "DataGridTextBoxColumn
Class" (look there for a good complete example).

myColumnTextColumn = New DataGridTextBoxColumn(pd)
dataGrid1.DataSource = myTable
dataGrid1.TableStyles.Add(New DataGridTableStyle())
dataGrid1.TableStyles(0).GridColumnStyles.Add
(myColumnTextColumn)

I haven't literally tried per this example, but I believe
it's then just myColumnTextColumn.Format = "d".

hth,

Bill
-----Original Message-----
I have a large data grid with several rows that contain
dates. I want to display the date only(no time). Even
when I use the trunc function in Oracle the rows show a
time of 12:00:00 am.
What I get now: 11/11/2003 12:00:00 am What I want is
just the 11/11/2003. I have searched help and haven't
been able to find this particular topic.
 
Back
Top