Date Format

C

Charles A. Lackman

Hello,

I an trying to get away from using a Date Time Picker and would like to know
how to make a textbox format to a date, i.e.

6604 would be converted to 06/06/04

and if the user type in
6/6/04 it would be converted to 06/06/04

I have experimented with formating the information with little to no success
ie.

textbox1.text = format(textbox2.text, "0#/0#/0#")

or even

Dim ADate as Date
ADate = CType(TextBox2.text, Date)
Format(ADate, "mm/dd/yy")
Textbox1.text = ADate

Anyway, I have tried alot of different ways to make it work with no success.

Any suggestions and examples will be greatly appreciated.

Chuck

P.S. I have wondered if an input mask would solve this problem, but I an not
sure how to accomplish this.
 
C

Cor Ligthert

Charles,

Before I give an answer, what does this date mean in your situation?

11111

Cor

"Charles A. Lackman"
 
H

Herfried K. Wagner [MVP]

Charles A. Lackman said:
I an trying to get away from using a Date Time Picker and would
like to know how to make a textbox format to a date, i.e.

6604 would be converted to 06/06/04

and if the user type in
6/6/04 it would be converted to 06/06/04

I have experimented with formating the information with little to no
success ie.

textbox1.text = format(textbox2.text, "0#/0#/0#")

This won't work.
Dim ADate as Date
ADate = CType(TextBox2.text, Date)

Use 'DateTime.ParseExact' with a specific format instead.
Format(ADate, "mm/dd/yy")

Notice that "mm" is the pattern for minutes, use "MM" instead.
 
G

Guest

Cor Ligthert said:
Charles,

Before I give an answer, what does this date mean in your situation?

11111

Cor

Upstair may consider a way to manipulate the date format in your desired
way, like yy/mm/dd or dd/mm/yy or yy/dd/mm or mm/dd/yy or few more
combinations. If it's in yy/mm/dd, then 11111 must be in 11/11/1 but this is
not in right format of your desire, so you need to convert it in 11/11/01
either by using your own defined function call or thr built-in calls under
Date/ Time category, depending on how you get that 11111.
 
G

Guest

I have experimented with formating the information with little to no success
ie.

textbox1.text = format(textbox2.text, "0#/0#/0#")

Sure this one is failed. If a user enters 12/12/4, then the above line would
give out an error msg coz you can't add a 0 in front of 12.

You may add a length check when a user enters a date. If it's less than 6,
then the entry is not allowed. In this way, you may have easier life to
format the string in your own way.
But you can also do it without previous check. feeding in two digits every
time and adding a 0 if it's a single digits would work too.

it's lots of ways to implement that by the way...
 
C

Cor Ligthert

Susumi
Upstair may consider a way to manipulate the date format in your desired
way, like yy/mm/dd or dd/mm/yy or yy/dd/mm or mm/dd/yy or few more
combinations. If it's in yy/mm/dd, then 11111 must be in 11/11/1 but this
is
not in right format of your desire, so you need to convert it in 11/11/01
either by using your own defined function call or thr built-in calls under
Date/ Time category, depending on how you get that 11111.

And why it is not?
01:11:2011

Or

11:01:2011

Cor
 
C

Chris Dunaway

Hello,

I an trying to get away from using a Date Time Picker and would like to know
how to make a textbox format to a date, i.e.

Just out of curiosity, why? My only guess is that you don't want the
calendar portion of the DateTimePicker. Well you can get rid of that by
setting the ShowUpDown property of the control to True. If you set the
DateTimePicker's ShowUpDown property to True, set the Format property to
Custom and set the CustomFormat property to the desired Date format, you
have a textbox that only accepts dates in the format you want. You also
have an updown control that makes it easy for the user to change the date.
Or the user can just type in a date and it will prevent them from entering
an incorrect one.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Need help with date format 5
Date Conversions 2
Preserving date format in VB 3
Text cast to Date & Time 4
Vba Date$ 1
Dates from InputBox 2
Stumped By Dates 4
Date Formats & Display 5

Top