Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am calling a list stored procedure using c#. This sp return a dataset. the Tables in dataset hava datetime columns. But in that column values not getting milliseconds even value contain milliseconds in database. How to get datatable with milliseconds.
Posted
Updated 16-Oct-12 22:22pm
v2
Comments
Sushil Mate 17-Oct-12 3:13am    
Does the database has date time column in milliseconds?
Narra sreenu 17-Oct-12 4:21am    
yes
Sushil Mate 17-Oct-12 4:24am    
can you show us your stored procedure?
Narra sreenu 17-Oct-12 4:31am    
If sp executes in DataBase datatable displayed as:

UserId UserName FirstName LastName CreatedOn
146 adarshbandi Adarsh Bandi 2012-10-13 13:30:11.563


If sp executes in c# Datatable displayed as:

UserId UserName FirstName LastName CreatedOn
146 adarshbandi Adarsh Bandi 2012-10-13 13:30:11 PM
Narra sreenu 17-Oct-12 4:36am    
ALTER PROCEDURE [dbo].[sp_TypingTutor_Admin_Granted_UsersList]
AS
BEGIN
select UserId,UserName,

FirstName,
LastName,

cast(DateofBirth as smalldatetime) as 'Date of Birth',

LastUpdatedOn as 'CreatedOn' from users where usertype=2 and userid is not NULL and deletedyn=0
end

try this code in your application...

format(dr["DateValue"].ToString(), "dd mmm yyyy hh:nn:ss.fff") to get milliseconds

Thank you
 
Share this answer
 
u can use DATEPART() for this..check example for this

http://www.w3schools.com/sql/func_datepart.asp[^]
 
Share this answer
 
Hi,

See the below link. It might be help you to find the solution.

http://www.csharp-examples.net/string-format-datetime/[^]

Thanks,
Viprat
 
Share this answer
 
SQL
ALTER PROCEDURE [dbo].[sp_TypingTutor_Admin_Granted_UsersList]
AS 
BEGIN
	select UserId,UserName,
			FirstName,
			LastName,
			DateofBirth as 'Date of Birth',
			LastUpdatedOn as 'CreatedOn' from users where usertype=2 and userid is not NULL and deletedyn=0

END
 
Share this answer
 
The data Table has milliseconds, if you check data row item array. You'll have to change the string format to your need.

Here is an example passing it to SQL string:

C#
strSql.AppendFormat(" EventDate = '{0}' AND", String.Format("{0:MM/dd/yyyy HH:mm:ss.fff}", dr[EventDate]));


This link has all the formats in detail:
http://www.csharp-examples.net/string-format-datetime/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900