Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type "Time" in SQL Server and C#

Is there any way that I can create the type time in C# to be compatible with the type time of the SQL server?

like image 708
Diego Avatar asked Jun 02 '10 13:06

Diego


People also ask

What datatype is used for time?

The TIMESTAMP data type consists of a date and time, with optional time zone.

What data type is time in C#?

In C# a DateTime data type is a struct type that represents an instant of time.


2 Answers

According to MSDN:

Mapping CLR Parameter Data

You're looking for the TimeSpan type.

like image 176
Justin Niessner Avatar answered Oct 24 '22 21:10

Justin Niessner


try using the below date formatter in C#.

DateTime dateTime = DateTime.Now; string text = dateTime.ToString("yyyy'-'MM'-'dd HH':'mm':'ss.fff");

This will lead to the same format as sql date format 'yyyy-mm-dd hh:mm:ss.fff'

Thanks!

like image 22
Parul Bansal Avatar answered Oct 24 '22 19:10

Parul Bansal