Reputation: 43
I am using a sql server database and i am storing the time value in the datetime variable. I am developing a booking system application in vb.net. When I want to view already made bookings using datagridview and by implementing dataadapter and dataset it shows the time column with system date which was saved with time when the record was inserted. Now I want to view only time in the Time field when extracting the data....What should i do now??
Upvotes: 0
Views: 513
Reputation: 11263
You can also just do the formatting directly in the datagridview with a dataformatstring like this:
<asp:BoundField DataField="TimeStart" HeaderText="Time In" DataFormatString="{0:t}" />
Upvotes: 2
Reputation: 700362
The DateTime
value is shown with the default formatting. You should specify the formatting for the column in the grid view.
Example:
bookingDataGridView.Columns["Created"].DefaultCellStyle.Format = "yyyy-MM-dd";
These resources should help you to specify the format, and picking a format string that displays the date in the way you want:
How to: Format Data in the Windows Forms DataGridView Control
Standard Date and Time Format Strings
Custom Date and Time Format Strings
Upvotes: 0
Reputation: 15579
keep it as it is in the database.. once you read the data from the database into VB and assign to a variable then do something like this
Dim date1 As Date = #6/1/2008 7:47AM# // this value being read from the db
Console.WriteLine(date1.ToString())
use the following:
' Get date-only portion of date, without its time.
Dim dateOnly As Date = date1.Date
' Display date using short date string.
Console.WriteLine(dateOnly.ToString("d"))
' Display date using 24-hour clock.
Console.WriteLine(dateOnly.ToString("g"))
Console.WriteLine(dateOnly.ToString("MM/dd/yyyy HH:mm"))
' The example displays the following output to the console:
' 6/1/2008 7:47:00 AM
' 6/1/2008
' 6/1/2008 12:00 AM
' 06/01/2008 00:00
or
Dim dtmTest As Date
dtmTest = DateValue(date1)
Upvotes: 0