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

Please help with converting a Date and a Time string after concate

P: n/a
I have 2 strings, "12/28/2005" and "16:44:54". I need to conatenate them and
convert them to datetime format so I can assign them to a datetime field in a
datarow. The time is now being converted to the date "12/28/2005". and I
don't know how to concatenate them since "+" won't work after I convert them.
Thanks, Alpha

if (result == "00")
{
char[] separator = {','};
char[] intSep = {'.'};
string lastDate, lastTime, lastMilleage;
DataRow drVeh = dsVehicle.Tables["VehDetail"].Rows[VListing.CurrentRowIndex];
DialogResult msgRet;

string[] replySeparated = ATSReply.Split(separator);
lastDate = replySeparated[2];
lastTime = replySeparated[3];
lastMilleage = replySeparated[4];
lastMilleage = lastMilleage.Substring(0, lastMilleage.Length - 3);
string[] intLastMilleage = lastMilleage.Split(intSep);

msgRet = MessageBox.Show("Would you like to update the vehicle odometer to
" + lastMilleage +
" and the last odometer read date to " + lastDate + " and the read time to
" +
lastTime, "Live Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(msgRet == DialogResult.Yes)
{
DateTime DatelastDate = Convert.ToDateTime(lastDate);
DateTime TimeLastTime = Convert.ToDateTime(lastTime);
// DateTime lastDateTime = DatelastDate + TimeLastTime;

drVeh["LastOdometerDate"] = DatelastDate;
drVeh["LastOdometerReading"] = Convert.ToInt32(intLastMilleage[0]);
drVeh.EndEdit();

}

}
Dec 29 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,
Sorry for the re-post ,check the DateTimeFormatInfo class for build format
strings
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
I have 2 strings, "12/28/2005" and "16:44:54". I need to conatenate them
and
convert them to datetime format so I can assign them to a datetime field
in a
datarow. The time is now being converted to the date "12/28/2005". and I
don't know how to concatenate them since "+" won't work after I convert
them.
Thanks, Alpha

if (result == "00")
{
char[] separator = {','};
char[] intSep = {'.'};
string lastDate, lastTime, lastMilleage;
DataRow drVeh =
dsVehicle.Tables["VehDetail"].Rows[VListing.CurrentRowIndex];
DialogResult msgRet;

string[] replySeparated = ATSReply.Split(separator);
lastDate = replySeparated[2];
lastTime = replySeparated[3];
lastMilleage = replySeparated[4];
lastMilleage = lastMilleage.Substring(0, lastMilleage.Length - 3);
string[] intLastMilleage = lastMilleage.Split(intSep);

msgRet = MessageBox.Show("Would you like to update the vehicle odometer to
" + lastMilleage +
" and the last odometer read date to " + lastDate + " and the read time to
" +
lastTime, "Live Update", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if(msgRet == DialogResult.Yes)
{
DateTime DatelastDate = Convert.ToDateTime(lastDate);
DateTime TimeLastTime = Convert.ToDateTime(lastTime);
// DateTime lastDateTime = DatelastDate + TimeLastTime;

drVeh["LastOdometerDate"] = DatelastDate;
drVeh["LastOdometerReading"] = Convert.ToInt32(intLastMilleage[0]);
drVeh.EndEdit();

}

}

Dec 29 '05 #2

P: n/a
Hi,

You could use DateTime.ParseExact( date_String + " " + time_String,
"MM/dd/yyyy HH:mm:ss, CultureInfo.InvariantCulture.DateTimeFormat );
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
I have 2 strings, "12/28/2005" and "16:44:54". I need to conatenate them
and
convert them to datetime format so I can assign them to a datetime field
in a
datarow. The time is now being converted to the date "12/28/2005". and I
don't know how to concatenate them since "+" won't work after I convert
them.
Thanks, Alpha

if (result == "00")
{
char[] separator = {','};
char[] intSep = {'.'};
string lastDate, lastTime, lastMilleage;
DataRow drVeh =
dsVehicle.Tables["VehDetail"].Rows[VListing.CurrentRowIndex];
DialogResult msgRet;

string[] replySeparated = ATSReply.Split(separator);
lastDate = replySeparated[2];
lastTime = replySeparated[3];
lastMilleage = replySeparated[4];
lastMilleage = lastMilleage.Substring(0, lastMilleage.Length - 3);
string[] intLastMilleage = lastMilleage.Split(intSep);

msgRet = MessageBox.Show("Would you like to update the vehicle odometer to
" + lastMilleage +
" and the last odometer read date to " + lastDate + " and the read time to
" +
lastTime, "Live Update", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if(msgRet == DialogResult.Yes)
{
DateTime DatelastDate = Convert.ToDateTime(lastDate);
DateTime TimeLastTime = Convert.ToDateTime(lastTime);
// DateTime lastDateTime = DatelastDate + TimeLastTime;

drVeh["LastOdometerDate"] = DatelastDate;
drVeh["LastOdometerReading"] = Convert.ToInt32(intLastMilleage[0]);
drVeh.EndEdit();

}

}

Dec 29 '05 #3

P: n/a
Thank you Ignacio. That worked out great!

Alpha

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

You could use DateTime.ParseExact( date_String + " " + time_String,
"MM/dd/yyyy HH:mm:ss, CultureInfo.InvariantCulture.DateTimeFormat );
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
I have 2 strings, "12/28/2005" and "16:44:54". I need to conatenate them
and
convert them to datetime format so I can assign them to a datetime field
in a
datarow. The time is now being converted to the date "12/28/2005". and I
don't know how to concatenate them since "+" won't work after I convert
them.
Thanks, Alpha

if (result == "00")
{
char[] separator = {','};
char[] intSep = {'.'};
string lastDate, lastTime, lastMilleage;
DataRow drVeh =
dsVehicle.Tables["VehDetail"].Rows[VListing.CurrentRowIndex];
DialogResult msgRet;

string[] replySeparated = ATSReply.Split(separator);
lastDate = replySeparated[2];
lastTime = replySeparated[3];
lastMilleage = replySeparated[4];
lastMilleage = lastMilleage.Substring(0, lastMilleage.Length - 3);
string[] intLastMilleage = lastMilleage.Split(intSep);

msgRet = MessageBox.Show("Would you like to update the vehicle odometer to
" + lastMilleage +
" and the last odometer read date to " + lastDate + " and the read time to
" +
lastTime, "Live Update", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if(msgRet == DialogResult.Yes)
{
DateTime DatelastDate = Convert.ToDateTime(lastDate);
DateTime TimeLastTime = Convert.ToDateTime(lastTime);
// DateTime lastDateTime = DatelastDate + TimeLastTime;

drVeh["LastOdometerDate"] = DatelastDate;
drVeh["LastOdometerReading"] = Convert.ToInt32(intLastMilleage[0]);
drVeh.EndEdit();

}

}


Dec 29 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.