Avatar of jaydwest
jaydwest

asked on 

Formatting Date in WIndows Form TextBox or Masked TextBox

I have a date field that I want to use a Text Box or Masked Text Box to enter the date in the format mm/dd/yyyy.  I'm currently using a Masked Text Box and I can enter the date 07/18/2008.  The date in the SQL Table is 7/18/2008.  That's what I want.  The Mask on this field is 00/00/0000.  However when the record with the date is recalled and displayed on form, the date is displayed in the format 71/82/008.  

I give up.  What is the best way to enter a date in the format mm/dd/yyyy and display it in the format mm/dd/yyyy.  I tried formatting the date string manually and setting it in the Form_Load event, but the data doesn't seem to be available for this event.  

Why does VB.net have to hurt so much.  The formatting seems totally different from every other MS package I have used!

HEEEEEEEEEEEEEEEEEEEEEEEELP
.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
jaydwest
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Hi jaydwest,

Don't know how do you get the value from the SQL and add it to the masked text box but the right format is MM/dd/yyyy.

If you set it manually it will work for shure.

Ex:
Me.MaskedTextBox1.Text = Now.Date.ToString("MM/dd/yyyy")
Avatar of margajet24
margajet24
Flag of Singapore image

use DateTime.TryParse() to check if it is valid date
Avatar of jaydwest
jaydwest

ASKER

This is so frustrating.  This is a bound form with a bound date field.  The date is automatically loaded by VB.net although it doesn't seem to happen in the Form_Load event.  At least I cannot seem to see the date text in the event.  

THis is a simple and basic task in most development platforms.  I don't understand why no one seems to know the answer for this.  

How do you guys display a date in a specific format that is bound to a data table and is a valid date?

Thanks for your help.
Avatar of jaydwest
jaydwest

ASKER

Because I don't want my user to have to hit an enter or tab between month, day, year and I don't want the calendar icon to appear.

This is so incredibly bizarre.  This is a basic date control.  I cannot believe that no one (including MS) has a simple way to display a date in MM/dd/yyyy format.  

ASKER CERTIFIED SOLUTION
Avatar of jaydwest
jaydwest

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo