Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

format date in text box control

Posted on 2003-11-17
5
Medium Priority
?
1,112 Views
Last Modified: 2012-05-04
I have a form with an underlying dataset (from a sql server db) that is bound to various textboxes.  A couple of the fields in the dataset contain dates.  Is there a way to format the dates in the text boxes.

Currently they display as ‘06/10/2003 00:00:00’

I need them to display as 06/10/2003.

Is this possible?
0
Comment
Question by:WingYip
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Expert Comment

by:ob2
ID: 9763177
Easy Peasy

1) TextBox.Text = String.Format("{0:d}", Date)

Where d is always lowercase for short date and where date is the date from your dataset.
0
 
LVL 3

Accepted Solution

by:
the-edge earned 200 total points
ID: 9763226
use the Binding.Format Event

search "Binding.Format Event" in msdn for further details

from msdn:
Remarks
The Format event occurs both when data is pushed from the data source into the control, and when the data is pulled from the control into the data source. When the data is pushed from the data source into the control, the Binding will use the Format event to put the formatted data into the control. When the data is pushed from the control into the data source, the Binding will first parse the data using the Parse event, then format the data and push the it into the control.

The Format and Parse events allow you to create custom formats for displaying data. For example, if the data in a table is of type Decimal, you can display the data in the local currency format by setting the Value property of the ConvertEventArgs object to the formatted value in the Format event. You must consequently unformat the displayed value in the Parse event.

The Format event occurs whenever the Current value of the BindingManagerBase changes, which includes:

The first time the property is bound.
Any time the Position changes.
Whenever the data-bound list is sorted or filtered, which is accomplished when a DataView supplies the list.
The Format event also occurs after the Parse event. For example, when a control loses focus, its contents are parsed. Immediately afterwards, as new data is pushed into the control, the Format event occurs allowing the new contents to be formatted.



the edge
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10268075
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: ob2 {http:#9763177} & the-edge {http:#9763248}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0
 
LVL 1

Author Comment

by:WingYip
ID: 10280269
Have just tested the code.

the-edge gets the points

Thanks

Wing
0

Featured Post

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question