How to enter date in the text box?

  • Thread starter Thread starter Mehbs
  • Start date Start date
M

Mehbs

Hi guys:

I am very new to C# and would really appreciate if someone please help.
This is my first project and I am learning c#.

I have to create a form where user enters start date and end date. I will
use text boxes for both dates.

How can I format so user does not have to enter slashes and it display in
date format? ie. 01/01/2007.

Thank you.
 
Mehbs said:
Hi guys:

I am very new to C# and would really appreciate if someone please help.
This is my first project and I am learning c#.

I have to create a form where user enters start date and end date. I will
use text boxes for both dates.

How can I format so user does not have to enter slashes and it display in
date format? ie. 01/01/2007.

Why text boxes for the date? There are other controls that are designed
to specifically support this type of validated entry. I would suggest a
DateTimePicker with a custom format of MM/dd/yyyy. If the
DateTimePicker is too restricted then a MaskedTextBox with mask set to
00/00/0000 should also work.
 
Hi,

You better use the DateTimePicked and/or maskedTextBox
 
Thanks guys.

Now how do I get rid of time. I just need the date.
For example my dateticket name is dtperiod. When I try to display dtperiod,
it displays date and time.

Thanks
 
Mehbs said:
Thanks guys.

Now how do I get rid of time. I just need the date.
For example my dateticket name is dtperiod. When I try to display dtperiod,
it displays date and time.

How are you displaying it? If you use DateTime.ToShortDateString, that
should do it. Or pass in a custom format to ToString. Ex:

Console.WriteLine (dtperiod.ToString("dd-MM-yyyy"));

If you want just the date component you can access dtperiod.Date. Note
that it will still contain the time elements but they will be set to
00:00:00.
 

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

Back
Top