Click to See Complete Forum and Search --> : Add milliseconds to DataTable
laby
February 5th, 2008, 03:19 AM
Hi .....
How can i add milliseconds to datatable?
i am adding like this.
dataSet1.Tables["T_Log"].Columns.Add(new DataColumn(_customer.GetColumnName(colCount), typeof(System.DateTime)));
regards
laby
MMH
February 5th, 2008, 03:43 AM
Is this what you are looking for ?
dataSet1.Tables["T_Log"].Columns.Add(new DataColumn(_customer.GetColumnName(colCount), typeof(System.DateTime.Now.Millisecond.ToString())));
laby
February 5th, 2008, 04:10 AM
hi
thanks for the reply
No.my data is "10:03:45.74 ".while adding to datatable millisecond is missing.how can i add milliseconds to datatable.
regards
laby
TheCPUWizard
February 5th, 2008, 07:41 AM
You cant do it with a datetime field in the DB. You would have to use either a double or a string.
Values with the datetime data type are stored internally by the SQL Server 2005 Database Engine as two 4-byte integers. The first 4 bytes store the number of days before or after the base date: January 1, 1900. The base date is the system reference date. The other 4 bytes store the time of day represented as the number of 1/300-second units after midnight.
http://msdn2.microsoft.com/en-us/library/ms187819.aspx
laby
February 5th, 2008, 11:13 PM
thanks
so if i am using datatype as datetime,i am not able to add milliseconds to
datatable .Is there any other solution for this
regards
laby
TheCPUWizard
February 6th, 2008, 06:11 AM
I already gave you the two most common solutions...
You would have to use either a double or a string.
laby
February 11th, 2008, 12:55 AM
now i am adding datatype as string to datatable for time field.but in my application vr providing Search based on time.how can i search for time,when i use (<,>,<=,>=)
regards
laby
TheCPUWizard
February 11th, 2008, 06:14 AM
now i am adding datatype as string to datatable for time field.but in my application vr providing Search based on time.how can i search for time,when i use (<,>,<=,>=)
regards
laby
If that is what you want to do, then you would be better using a numberical type. Store the data using a integer with enough bits to hold the number of milliseconds since some starting time. If you are using SQLServer2005 or later, you could also create a new type using C#.....
laby
February 11th, 2008, 10:39 PM
thanks for the reply
But i am reading Data from a log file to datatable.For searching i am using dataview.RowFilter method
regards
laby
jmcilhinney
February 11th, 2008, 10:55 PM
You're asking the wrong question. If you're saving a DateTime value to a database then it already "contains" milliseconds, as every DateTime value does. If you aren't seeing the milliseconds then that's because you aren't displaying the value properly, not because it doesn't contain the right data. Try this:DateTime now = DateTime.Now;
MessageBox.Show(now.ToShortDateString());
MessageBox.Show(now.ToShortTimeString());
MessageBox.Show(now.ToLongTimeString());
MessageBox.Show(now.ToString());
MessageBox.Show(now.ToString("d/MM/yyyy h:mm:ss tt"));
MessageBox.Show(now.ToString("d/MM/yyyy HH:mm:ss.fff"));
MessageBox.Show(now.ToString("d/MM/yyyy HH:mm:ss.fffffff"));So you see, all the information is there and, if you want to see it, you simply have to show it properly.
laby
February 12th, 2008, 01:23 AM
The actual data is (10:07:32.76).i tried the way u told but the value from datatable contains only
10:07:32
thanks & regards
laby
jmcilhinney
February 12th, 2008, 02:43 AM
If your original data contains partial seconds and the data in the Datatable doesn't then you're obviously reading the data incorrectly. As you are yet to show us how you are reading the data it simply isn't possible for us to determine what you're doing wrong.
laby
February 12th, 2008, 03:06 AM
i am adding like this.
dataSet1.Tables["T_Log"].Columns.Add(new DataColumn(_customer.GetColumnName(colCount), typeof(System.DateTime)));
regards
laby
jmcilhinney
February 12th, 2008, 03:50 AM
i am adding like this.
dataSet1.Tables["T_Log"].Columns.Add(new DataColumn(_customer.GetColumnName(colCount), typeof(System.DateTime)));
regards
labyThat's adding the DataColumn to the DataTable. We don't care about that. We want to know how you're reading the data and adding it to a DataRow that is then added to the DataTable.
laby
February 12th, 2008, 05:52 AM
I am adding data from logfile to DATATABLE.The code is given below
dataSet1.Tables["T_Log"].Rows.Add(colData);
then dispalying using datagridview
dataGridView.Datasource=T_Log;.but here milliseconds is missing
regards
laby
jmcilhinney
February 12th, 2008, 06:33 AM
That still tells us nothing useful. Where are you getting the value from in the first place, how are you reading it and how are you adding it to the DataRow?
TheCPUWizard
February 12th, 2008, 06:53 AM
You're asking the wrong question. If you're saving a DateTime value to a database then it already "contains" milliseconds, as every DateTime value does.
jmcilhinney,
DateTime in SQLServer does NOT contain milliseconds. The resolution is 3.333333mS not 1mS!!!
As I postd very early in the thread, from the MSDN documentation.
Values with the datetime data type are stored internally by the SQL Server 2005 Database Engine as two 4-byte integers. The first 4 bytes store the number of days before or after the base date: January 1, 1900. The base date is the system reference date. The other 4 bytes store the time of day represented as the number of 1/300-second units after midnight.
Therefore is it IMPOSSIBLE to store times with 1mS resolution in a DateTime field in SQLServer. You MUST use some other data type.
laby
February 12th, 2008, 07:07 AM
I want to use search Conditions like(<,>,<=,>=) for TimeColumn.Currently my datatype is string .how can i do that
regards
laby
TheCPUWizard
February 12th, 2008, 07:24 AM
I want to use search Conditions like(<,>,<=,>=) for TimeColumn.Currently my datatype is string .how can i do that
regards
laby
I already told you, with a string field it will be very difficult and very low performance. If you are going to do calculations or comparisions, use a numberic field type with sufficient range to handle your information.
jmcilhinney
February 12th, 2008, 07:42 AM
jmcilhinney,
DateTime in SQLServer does NOT contain milliseconds. The resolution is 3.333333mS not 1mS!!!
As I postd very early in the thread, from the MSDN documentation.
Therefore is it IMPOSSIBLE to store times with 1mS resolution in a DateTime field in SQLServer. You MUST use some other data type.The OP keeps telling us that the original data only goes to two decimal places, so the greatest resolution needed will be 10 ms!!! Thus 3.333333 ms will be ample!!! The problem here is that the OP is dropping the partial seconds altogether somewhere between the original data and the database. Given that, despite my repeated attempts, the OP still refuses to provide that information I can only conclude they don't actually want any help and don't deserve it. I won't be wasting any more time on this one.
TheCPUWizard
February 12th, 2008, 07:48 AM
The OP keeps telling us that the original data only goes to two decimal places, so the greatest resolution needed will be 10 ms!!! Thus 3.333333 ms will be ample!!! The problem here is that the OP is dropping the partial seconds altogether somewhere between the original data and the database. Given that, despite my repeated attempts, the OP still refuses to provide that information I can only conclude they don't actually want any help and don't deserve it. I won't be wasting any more time on this one.
The (all too common) issue of the OP not providing the necessary information to be of assistance, does NOT mean that one should post known WRONG information in the forums. Or if the error was not known at the time of the posting, that it should not go back and be corrected.
These threads are read for years after they have been created. Often by tens of thousands of people.
Your post of
If you're saving a DateTime value to a database then it already "contains" milliseconds, as every DateTime value does.
is NOT correct.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.