Reputation: 600
In my SQL database, I have a column formatted as DateTime
and when I retrieve data from that column in ASP.NET, I catch it on the Date variable, than pass the value to textbox:
Dim Y As Date = dt.Rows(0)("SCH_DATE")
txtSchedDate.Text = Y.Date.ToString
but when I debug my website, the txtSchedDate.Text
still gives me the full DateTime
value:
7/17/2013 12:00:00 AM
is it possible to eliminate the time value here and just return the date?
Upvotes: 0
Views: 16052
Reputation: 4173
Besides answers above, you can try converting it in SQL server
SELECT CONVERT(varchar(15), GETDATE(), 11)
Keep in mind after converting it's VARCHAR(15)
instead of DATETIME
.
Upvotes: 1
Reputation: 34846
Once you have a Date
object, you can get the constituent pieces if you wish as well, like this:
Dim Y As Date = dt.Rows(0)("SCH_DATE")
txtSchedDate.Text = Y.Date.Year & "-" & Y.Date.Month & "-" & Y.Date.Day
Or you can use the custom and standard date and time format strings mentioned by others.
Upvotes: 0
Reputation: 63065
you can get date by txtSchedDate.Text = Y.Date.ToShortDateString()
Upvotes: 1
Reputation: 166336
Have you tried using something like
txtSchedDate.Text = Y.Date.ToString("MM/dd/yyyy")
or which ever format you wish to display.
Have a look at
DateTime.ToString Method (String)
Converts the value of the current DateTime object to its equivalent string representation using the specified format.
Custom Date and Time Format Strings
Standard Date and Time Format Strings
Upvotes: 5