Displaying Dates

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a windows form with several fields. One of the fields is a date. I use
DateTimePicker to enter and format the date. In my SQL table the date si
stored as follows "01/10/2005" and this is what I wont. When I display the
date with a 'fill or select' this is what I get '01/10/2005 12:00'. What am
I doing wrong? Please Help.
 
Norm,

You are doing nothing wrong. In SQL Server, the time is stored with the
date as well. As a matter of fact, the variable behind the date in your
date time picker has time information as well. However, the date time
picker only displays date information, and it drops the time information (or
rather, it doesn't give it any consideration when displaying it).

They are the same value. The reason you see 12:00 is that the 12:00 is
reflective of midnight on that day, which is technically the first moment of
that day.

Is there an error that you are getting, or is this just a general
concern?
 
I would like to remove the time from the textbox. This what I do in
DateTimePicker!

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MM/dd/yyyy";
txtDate.Text = dateTimePicker1.Text;

--
Norm Bohana


Nicholas Paldino said:
Norm,

You are doing nothing wrong. In SQL Server, the time is stored with the
date as well. As a matter of fact, the variable behind the date in your
date time picker has time information as well. However, the date time
picker only displays date information, and it drops the time information (or
rather, it doesn't give it any consideration when displaying it).

They are the same value. The reason you see 12:00 is that the 12:00 is
reflective of midnight on that day, which is technically the first moment of
that day.

Is there an error that you are getting, or is this just a general
concern?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

nbohana said:
I have a windows form with several fields. One of the fields is a date. I
use
DateTimePicker to enter and format the date. In my SQL table the date si
stored as follows "01/10/2005" and this is what I wont. When I display
the
date with a 'fill or select' this is what I get '01/10/2005 12:00'. What
am
I doing wrong? Please Help.
 
Ahh, you didn't mention that you were binding it to a textbox.

When you create the binding, what you can do is subscribe to the Parse
and the Format events on the binding. You can use this to format the date
as you wish in the textbox, as well as parse the date when the text is set
and needs to be persisted back to the value.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

nbohana said:
I would like to remove the time from the textbox. This what I do in
DateTimePicker!

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MM/dd/yyyy";
txtDate.Text = dateTimePicker1.Text;

--
Norm Bohana


Nicholas Paldino said:
Norm,

You are doing nothing wrong. In SQL Server, the time is stored with
the
date as well. As a matter of fact, the variable behind the date in your
date time picker has time information as well. However, the date time
picker only displays date information, and it drops the time information
(or
rather, it doesn't give it any consideration when displaying it).

They are the same value. The reason you see 12:00 is that the 12:00
is
reflective of midnight on that day, which is technically the first moment
of
that day.

Is there an error that you are getting, or is this just a general
concern?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

nbohana said:
I have a windows form with several fields. One of the fields is a date.
I
use
DateTimePicker to enter and format the date. In my SQL table the date
si
stored as follows "01/10/2005" and this is what I wont. When I display
the
date with a 'fill or select' this is what I get '01/10/2005 12:00'.
What
am
I doing wrong? Please Help.
 
I am sorry, Thanks much.
--
Norm Bohana


Nicholas Paldino said:
Ahh, you didn't mention that you were binding it to a textbox.

When you create the binding, what you can do is subscribe to the Parse
and the Format events on the binding. You can use this to format the date
as you wish in the textbox, as well as parse the date when the text is set
and needs to be persisted back to the value.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

nbohana said:
I would like to remove the time from the textbox. This what I do in
DateTimePicker!

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MM/dd/yyyy";
txtDate.Text = dateTimePicker1.Text;

--
Norm Bohana


Nicholas Paldino said:
Norm,

You are doing nothing wrong. In SQL Server, the time is stored with
the
date as well. As a matter of fact, the variable behind the date in your
date time picker has time information as well. However, the date time
picker only displays date information, and it drops the time information
(or
rather, it doesn't give it any consideration when displaying it).

They are the same value. The reason you see 12:00 is that the 12:00
is
reflective of midnight on that day, which is technically the first moment
of
that day.

Is there an error that you are getting, or is this just a general
concern?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have a windows form with several fields. One of the fields is a date.
I
use
DateTimePicker to enter and format the date. In my SQL table the date
si
stored as follows "01/10/2005" and this is what I wont. When I display
the
date with a 'fill or select' this is what I get '01/10/2005 12:00'.
What
am
I doing wrong? Please Help.
 
Nicholas, I am sorry, I cannot find out how to implement your suggestion. I
found the events ok, but I do not know how to setup it up in the textbox.
Can you point me in the right direction please!!
--
Norm Bohana


Nicholas Paldino said:
Ahh, you didn't mention that you were binding it to a textbox.

When you create the binding, what you can do is subscribe to the Parse
and the Format events on the binding. You can use this to format the date
as you wish in the textbox, as well as parse the date when the text is set
and needs to be persisted back to the value.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

nbohana said:
I would like to remove the time from the textbox. This what I do in
DateTimePicker!

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MM/dd/yyyy";
txtDate.Text = dateTimePicker1.Text;

--
Norm Bohana


Nicholas Paldino said:
Norm,

You are doing nothing wrong. In SQL Server, the time is stored with
the
date as well. As a matter of fact, the variable behind the date in your
date time picker has time information as well. However, the date time
picker only displays date information, and it drops the time information
(or
rather, it doesn't give it any consideration when displaying it).

They are the same value. The reason you see 12:00 is that the 12:00
is
reflective of midnight on that day, which is technically the first moment
of
that day.

Is there an error that you are getting, or is this just a general
concern?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have a windows form with several fields. One of the fields is a date.
I
use
DateTimePicker to enter and format the date. In my SQL table the date
si
stored as follows "01/10/2005" and this is what I wont. When I display
the
date with a 'fill or select' this is what I get '01/10/2005 12:00'.
What
am
I doing wrong? Please Help.
 

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