-1

I have a stored procedure which input is from the type datetime. i.e. I transfer the input 2014-01-13T16:55:03.370 ,while running the stored procedure from the sql server.

Now I want to execute a stored procedure from the application.So I tried to use parameter having System.DateTime type.Looks like it is not corresponds to sql datetime. Which type should I use for that?

UPD. I didn`t get the answer for my question. So I`ll try to make my question more clear. In SQL SErver database tables the values of the type datetime are saved.I am writing a stored procedure which looks for this values .I mean I need to get a parameter from the user of the for yyyy-mm-ddThh:mm:ss:.mmmm

YAKOVM
  • 9,805
  • 31
  • 116
  • 217
  • 3
    Show your code & exception you are getting – Rajeev Kumar Jan 14 '14 at 12:21
  • 3
    Sure - the .NET `DateTime` corresponds to the SQL Server `DATETIME`. The only "issue" you might run into is a question of **range** - .NET goes from `01-01-0001` to `31-12-9999` while SQL Server's `DATETIME` start at year 1753 (`DATE` or `DATETIME2` in SQL Server **2008** and newer don't have that limit anymore) – marc_s Jan 14 '14 at 12:23

2 Answers2

1

from MSDN:

GetDate() is a inbuilt function in sql, for c# you can use follwing:

  DateTime CurrentDate;
  CurrentDate = Convert.ToDateTime(DateTime.Now.ToString("dd-MMM-yyyy"));

I guess you can pass this variable through to the procedure call parameters?

or, search the site again and read: Function that creates a timestamp in c#

Community
  • 1
  • 1
Rich
  • 867
  • 7
  • 12
  • 3
    You should **never** need to convert a `DateTime` to a string if the very next operation you're going to perform is to convert it back into a `DateTime`. You code looks like it's trying to remove the time portion from `DateTime.Now` - something more easily achieved with `DateTime.Now.Date` – Damien_The_Unbeliever Jan 14 '14 at 13:11
1

Here you can find samples on data time conversions between SQL and C#, depending on the date data types you use

Shachaf.Gortler
  • 5,655
  • 14
  • 43
  • 71