Reputation: 10364
I am new to vb.net so apologies in advance if im asking a glaringly obvious one.
I have declared the following code in my pageload, it displays todays date in a label however it was displaying the date and time.
It originally said DateTime but I changed it to just Date in the hope this would work but it continued to display the time also.
I have used the left operator for now to trim it down to 10 characters however I would like to know what I should have done if id only wanted the date and not the time without having to trim the results.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dtNow As Date = Date.Now
time_stamp_entryLabel1.Text = Left(dtNow.ToString, 10)
End Sub
Upvotes: 1
Views: 8638
Reputation: 276
Here's how to do it in aspx
<asp:Label ID="DateLabel" runat="server" Text='<%# String.Format(Date.ParseExact("09/09/1955", "d", New System.Globalization.CultureInfo("en-US"))) %>' />
Upvotes: 0
Reputation: 6996
Code
Dim d As DateTime = Now
d.ToLongDateString
d.ToShortDateString
d.ToString("d")
d.ToString("yyyy-MM-dd")
Results
Wednesday, December 10, 2008
12/10/2008
12/10/2008
2008-12-10
Upvotes: 4