Date and Time field concatination

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I have field with a Date and a field with a Time; is there anyway to make a
complete DateTime using an expression in ADO.NET?
I don't have an option to do this in a database before getting the data into
the app.

Thanks,
Joe
 
I have field with a Date and a field with a Time; is there anyway to make a
complete DateTime using an expression in ADO.NET?
I don't have an option to do this in a database before getting the data into
the app.

Thanks,
Joe

You can use the datetime constructor and pass it the year, month, day, hour
and minute from your date and time and then assign that to the row and
column of the dataset
 
Rad,

I think that you can even do that in one time.

dr.MyDate = New DateTime(2007, MyMonth, MyDay, MyHour, MyMinute, 0)
For VB.Net and for C#
dr.MyDate = new DateTime(2007, MyMonth, MyDay, MyHour, MyMinute, 0);

Cor
 
Hi Joe,
Thanks for Rad and Cor's reply.

I just want to check if the issue has been resolved. If there is anything
we can help with.
Please feel free to post here and we will follow up.

Have a great day,
Sincerely,
Wen Yuan
 
Actually those replies didn't answer my question. I want to know if this can
be done in an expression.
 
Hello Joe,

I got it. But I need some time to perform some research.
Please wait me one or two days. I will update here as soon as I can get any
information.

Have a great day,
Sincerely,
Wen Yuan
 
Hi Wen Yuan,

Can you make me 40 years younger.
If you don't understand it than mail me?

:-)

Cor
 
Hi Joe.

Sorry, as Cor said, I'm afraid the expression column in Ado.net can't
provide this feature for you.

I have tried to substring the date filed and time filed, and then combined
them to new datetime filed.
Such as:
Columns.Add("realyDate", typeof(System.DateTime),
@"SubString(CONVERT(date,System.String),1,10)+'
'+SubString(CONVERT(date,System.String),12,19)");

But this methond can not work fine with "2003/03/03". Datetime typed column
will shorten it as "2003/3/3". For this reason, I failed to substring date.

The only way to achive this is you should have to modify the query command.
Convert date and time to nvarchar as "yyyy-mm-ddThh:mm:ss.mmm"
Such as (in SQL database):
SqlDataAdapter ada = new SqlDataAdapter("select
c1,convert(nvarchar,date,126) as date ,convert(nvarchar,time,126) as time
from table_1", strConnect);

Otherwise, as Rad and Cor said, travel through each row of your table,
create a datetime object for the new column.

Please feel free to let me know if you have anything unclear. I'm glad to
assist you.

Hope this helps,
Sincerely,
Wen Yuan
 
Back
Top