By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

Drop the time in Date field.

P: n/a
This is for a Win form.

SP sends back the PostMark date to my datagrid, shows proper date in
datagrid. When user clicks on datagrid, the code sends the current row to
text box. The text box shows the date and 12:00:00 AM. How do I get rid of
the time?

My code below.

int rowNum = dgDealerInfo.CurrentCell.RowNumber;
object Cell1 = dgDealerInfo[rowNum, 0];
object Cell2 = dgDealerInfo[rowNum, 1];
object Cell3 = dgDealerInfo[rowNum, 2];
object Cell4 = dgDealerInfo[rowNum, 3];
object Cell5 = dgDealerInfo[rowNum, 4];
string s = string.Format(Cell3 + System.Environment.NewLine + Cell4 +
System.Environment.NewLine + Cell5);
string s1 = string.Format(Cell1 + "");
string s2 = string.Format(Cell2 + "");
Nov 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi,

Use DateTime.ToShortDateFormat();

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Mike L" <Ca***@nospam.nospam> wrote in message
news:64**********************************@microsof t.com...
This is for a Win form.

SP sends back the PostMark date to my datagrid, shows proper date in
datagrid. When user clicks on datagrid, the code sends the current row to
text box. The text box shows the date and 12:00:00 AM. How do I get rid
of
the time?

My code below.

int rowNum = dgDealerInfo.CurrentCell.RowNumber;
object Cell1 = dgDealerInfo[rowNum, 0];
object Cell2 = dgDealerInfo[rowNum, 1];
object Cell3 = dgDealerInfo[rowNum, 2];
object Cell4 = dgDealerInfo[rowNum, 3];
object Cell5 = dgDealerInfo[rowNum, 4];
string s = string.Format(Cell3 + System.Environment.NewLine + Cell4 +
System.Environment.NewLine + Cell5);
string s1 = string.Format(Cell1 + "");
string s2 = string.Format(Cell2 + "");

Nov 17 '05 #2

P: n/a
I get an error. "Cannot implicitly convert type 'object' to 'System.DateTime'.

Here is my code.

DateTime Cell3 = dgDealerInfo[rowNum, 2];
ResultForm.SetTextBox(Cell3.ToShortDateString());
dgDealerInfo[rowNum, 2] is a cell in my datagrid on my winform.
ResultForm.SetTextBox is a method on my winform
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

Use DateTime.ToShortDateFormat();

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Mike L" <Ca***@nospam.nospam> wrote in message
news:64**********************************@microsof t.com...
This is for a Win form.

SP sends back the PostMark date to my datagrid, shows proper date in
datagrid. When user clicks on datagrid, the code sends the current row to
text box. The text box shows the date and 12:00:00 AM. How do I get rid
of
the time?

My code below.

int rowNum = dgDealerInfo.CurrentCell.RowNumber;
object Cell1 = dgDealerInfo[rowNum, 0];
object Cell2 = dgDealerInfo[rowNum, 1];
object Cell3 = dgDealerInfo[rowNum, 2];
object Cell4 = dgDealerInfo[rowNum, 3];
object Cell5 = dgDealerInfo[rowNum, 4];
string s = string.Format(Cell3 + System.Environment.NewLine + Cell4 +
System.Environment.NewLine + Cell5);
string s1 = string.Format(Cell1 + "");
string s2 = string.Format(Cell2 + "");


Nov 17 '05 #3

P: n/a
Mike L <Ca***@nospam.nospam> wrote:
I get an error. "Cannot implicitly convert type 'object' to 'System.DateTime'.


So cast the expression to a DateTime before trying to use it as one.

(Looking back to your original code, using x+"" to convert x to a
string is pretty nasty - use x.ToString(), or Convert.ToString(x).)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

P: n/a
You could also use:

DateTime myDate = DateTime.Now();
string.Format("{0:d}", myDate);

--

Derek Davis
dd******@gmail.com

"Mike L" <Ca***@nospam.nospam> wrote in message
news:64**********************************@microsof t.com...
This is for a Win form.

SP sends back the PostMark date to my datagrid, shows proper date in
datagrid. When user clicks on datagrid, the code sends the current row to
text box. The text box shows the date and 12:00:00 AM. How do I get rid
of
the time?

My code below.

int rowNum = dgDealerInfo.CurrentCell.RowNumber;
object Cell1 = dgDealerInfo[rowNum, 0];
object Cell2 = dgDealerInfo[rowNum, 1];
object Cell3 = dgDealerInfo[rowNum, 2];
object Cell4 = dgDealerInfo[rowNum, 3];
object Cell5 = dgDealerInfo[rowNum, 4];
string s = string.Format(Cell3 + System.Environment.NewLine + Cell4 +
System.Environment.NewLine + Cell5);
string s1 = string.Format(Cell1 + "");
string s2 = string.Format(Cell2 + "");

Nov 17 '05 #5

P: n/a
Thank you.

I cleaned up my code.

int rowNum = dgDealerInfo.CurrentCell.RowNumber;
string Cell1 = dgDealerInfo[rowNum, 0].ToString();
string Cell2 = dgDealerInfo[rowNum, 1].ToString();
string Cell3 = dgDealerInfo[rowNum, 2].ToString();
DateTime Cell4 = (DateTime) dgDealerInfo[rowNum, 3];
string Cell5 = dgDealerInfo[rowNum, 4].ToString();
string s = string.Format(Cell3 + System.Environment.NewLine +
string.Format("{0:d}", Cell4) + System.Environment.NewLine + Cell5);
ResultForm.SetTextBox(s);

"Jon Skeet [C# MVP]" wrote:
Mike L <Ca***@nospam.nospam> wrote:
I get an error. "Cannot implicitly convert type 'object' to 'System.DateTime'.


So cast the expression to a DateTime before trying to use it as one.

(Looking back to your original code, using x+"" to convert x to a
string is pretty nasty - use x.ToString(), or Convert.ToString(x).)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #6

P: n/a
Mike L <Ca***@nospam.nospam> wrote:
Thank you.

I cleaned up my code.

int rowNum = dgDealerInfo.CurrentCell.RowNumber;
string Cell1 = dgDealerInfo[rowNum, 0].ToString();
string Cell2 = dgDealerInfo[rowNum, 1].ToString();
string Cell3 = dgDealerInfo[rowNum, 2].ToString();
DateTime Cell4 = (DateTime) dgDealerInfo[rowNum, 3];
string Cell5 = dgDealerInfo[rowNum, 4].ToString();
string s = string.Format(Cell3 + System.Environment.NewLine +
string.Format("{0:d}", Cell4) + System.Environment.NewLine + Cell5);
ResultForm.SetTextBox(s);


Why are you calling string.Format twice? What are you trying to
actually *format* by the time you've concatenated the various strings
together?

(You might want to consider more meaningful names than Cell1, Cell2,
Cell3 etc too.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #7

P: n/a
I WAS calling string.Format twice because I'm still learning .Net programming.

I was using Cell name variables because I was still in draft stage. Now
that I know for sure what data I'm pulling through, I modified the variables.

int rowNum = dgDealerInfo.CurrentCell.RowNumber;
string sFEI = dgDealerInfo[rowNum, 0].ToString();
string sSite = dgDealerInfo[rowNum, 1].ToString();
string sName = dgDealerInfo[rowNum, 2].ToString();
DateTime dtPostMark = (DateTime)
dgDealerInfo[rowNum, 3];
string sAmount = dgDealerInfo[rowNum, 4].ToString();
string s = sName + System.Environment.NewLine +
string.Format("{0:d}", dtPostMark) + System.Environment.NewLine + sAmount;
ResultForm.SetTextBox(s);
ResultForm.SetDealerFEI(Cell1);
ResultForm.SetDealerSite(Cell2);
this.DialogResult = DialogResult.OK;
"Jon Skeet [C# MVP]" wrote:
Mike L <Ca***@nospam.nospam> wrote:
Thank you.

I cleaned up my code.

int rowNum = dgDealerInfo.CurrentCell.RowNumber;
string Cell1 = dgDealerInfo[rowNum, 0].ToString();
string Cell2 = dgDealerInfo[rowNum, 1].ToString();
string Cell3 = dgDealerInfo[rowNum, 2].ToString();
DateTime Cell4 = (DateTime) dgDealerInfo[rowNum, 3];
string Cell5 = dgDealerInfo[rowNum, 4].ToString();
string s = string.Format(Cell3 + System.Environment.NewLine +
string.Format("{0:d}", Cell4) + System.Environment.NewLine + Cell5);
ResultForm.SetTextBox(s);


Why are you calling string.Format twice? What are you trying to
actually *format* by the time you've concatenated the various strings
together?

(You might want to consider more meaningful names than Cell1, Cell2,
Cell3 etc too.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.