Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > seprate date part from datetime field
 

seprate date part from datetime field

If I bond a textbox to a date field in a database a time part is added to it how can I stop that so only date is showen in the textbox
I try SQL server - access (short date) - oracle (date) fields but it seems to be the same so the solution fron VB it self .
In VB 6 there was a format property but it is not there any more 
is there a some code or some thing to solve this
I think it is must be simple but ????
MigrationUser 1  Tuesday, June 24, 2003 12:03 AM
Try this user defined function in SQL database stored procedures:

CREATE FUNCTION dbo.dateString (@Date datetime)  
RETURNS char(10)

AS  
BEGIN 

DECLARE @retSTR as char(10)  

IF @Date is null 

set @retSTR = SPACE(10)

ELSE

set @retSTR =  CONVERT(char(10), @Date, 101)  

RETURN @retSTR

END


Use it in your stored procedures:

Select dateString(yourDate in SQL) as yourDate ....

Dan
MigrationUser 1  Sunday, June 29, 2003 12:12 AM
FYI: FormatDateTime still exists in VB.NET (just like VB6) and is in the Microsoft.VisualBasic Library.

Also, the Date Class has methods to print out only the Date in different formats.

Yet another way is to use the "d" formatter in the ToString method

And a forth way, because it wouldn't be fun without 10,000 ways to do the same thing is to pass in something like "mm/dd/yyyy" to the ToString Method

 ;) 

If you'd like to encapsulate this formatting process when using DataBinding, you can consume the Format Event of the DataBinding Class.
MigrationUser 1  Monday, June 30, 2003 4:02 AM

You can use google to search for other answers

Custom Search

More Threads

• DataGrid data loading blocks the application
• Windows Form & DataGridView with in User Control
• Case-insensitivity for individual columns in a datatable query
• Complex DataBinding with a DataRowView
• CheckedListBox Control does not display bound data!
• proplem with column expression when using the (sum) VS2005
• datagridview duplicate values
• To update the Database with OleDb.OleDbDataAdapter
• will some one tell me
• Drag & Drop row reordering on Databound DataGridView