Groups > Databases > Access Databases and AccessDataSource Control > Re: How to Stop Displaying 12am Time in VB ASP.NET from Date/Time field in Access DB




How to Stop Displaying 12am Time in VB ASP.NET from
Date/Time field in Access DB

How to Stop Displaying 12am Time in VB ASP.NET from Date/Time field in Access DB
Mon, 24 Mar 2008 18:11:03 +000
I am using VB in ASP.NET to display records from a table in Access.  The goal is
to display all records with a datestamp from today.  The problem is a timestamp
appears in ASP.NET even though there is no timestamp, just a date, in the
Date/Time field in the Access DB.  All records have the time 12:00:00 AM after
the date, and I do not want 12:00:00 AM to appear.  How do I get rid of it?


Here is my code:

--------------------------------------------------

 <%@ Page Explicit="True" Language="VB" %>

<html>
<head>

<title>Test Table</title>

<script runat="server">

Sub Page_Load
        
        Dim dbconn, sql, dbcomm, dbread
        dbconn = New
Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data
source=" & Server.MapPath("db_SIDteam.mdb"))
        dbconn.Open()
        
        Dim DtToday
        DtToday = "#" & Date.Today & "#"
        Label1.Text = DtToday
        
        sql = "SELECT * FROM tbl_Test WHERE Dt=" & DtToday
        Label2.Text = sql
        dbcomm = New Data.OleDb.OleDbCommand(sql, dbconn)
        dbread = dbcomm.ExecuteReader()
        customers.DataSource = dbread
        customers.DataBind()
        dbread.Close()
        dbconn.Close()

    End Sub
    
</script>
</head>

<body>

<form runat="server">

<h2></h2>
    <asp:Label ID="Label1"
runat="server"></asp:Label><br />
    <asp:Label ID="Label2"
runat="server"></asp:Label>

<asp:Repeater id="customers" runat="server">

<HeaderTemplate>
<table border="0" width="100%">
</HeaderTemplate>

<ItemTemplate>
<tr>
<td><%#Container.DataItem("ID")%></td>
<td><%#Container.DataItem("Dt")%></td>
</tr>
</ItemTemplate>

<FooterTemplate>
</table>
</FooterTemplate>

</asp:Repeater>

</form>
</body>
</html>

-------------------------------------------------- 



Here are the results in a browser:

-------------------------------------------------- 


#3/24/2008#
SELECT * FROM tbl_Test WHERE Dt=#3/24/2008#1
3/24/2008 12:00:00 AM2
3/24/2008 12:00:00 AM3
3/24/2008 12:00:00 AM

 --------------------------------------------------
Post Reply
Re: How to Stop Displaying 12am Time in VB ASP.NET from Date/Time field in Access DB
Mon, 24 Mar 2008 18:44:32 +000
Kitsune-chan:<td><%#Container.DataItem("Dt")%></td>


A better way would be to change it on the presentation side. Try this: 

<td><%#Container.DataItem("Dt").ToShortDateString%></td
>
Post Reply
Re: How to Stop Displaying 12am Time in VB ASP.NET from Date/Time field in Access DB
Mon, 24 Mar 2008 18:44:48 +000
Try the following: 

<td><%# String.Format("{0:d}",
Container.DataItem("Dt"))%></td>
Post Reply
Re: How to Stop Displaying 12am Time in VB ASP.NET from Date/Time field in Access DB
Mon, 24 Mar 2008 18:47:15 +000
It worked!  Thanks!!!

 

<td><%#Container.DataItem("Dt").ToShortDateString%></td
>

------------------------------------------- 

#3/24/2008#
SELECT * FROM tbl_Test WHERE Dt=#3/24/2008#1
3/24/20082
3/24/20083
3/24/2008
Post Reply
about | contact