Diego
Diego

Reputation: 91

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?

Upvotes: 9

Views: 10425

Answers (2)

Parul Bansal
Parul Bansal

Reputation: 11

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!

Upvotes: 1

Justin Niessner
Justin Niessner

Reputation: 245399

According to MSDN:

Mapping CLR Parameter Data

You're looking for the TimeSpan type.

Upvotes: 21

Related Questions