I am running a query from some C# code.
My problem is I don't know how to create a string in the correct format to include as part of my select statement.Code:select someColumn from someTable where CurrentDate-someDate > ElapsedTime
The format of the date column in sql server is:
mm/dd/yyyy hh:mm:ss AM/PM
Which SQL server are you using (Oracle, MS, MySQL - they are all a bit different)? I've done this exact same thing in C# or Managed C++ (can't remember).
sorry! i thought i had it on the first post I made, MS SQL Server 2005
I'm not sure if this helps but this will allow you to convert your MS SQL date/time into a C# object:
MSDN: DateTime Structure (System)Code:DateTime date_dt = DateTime.Parse(date_str);
Ahh, I think I just found your answer. Use function above to convert to an object. Then use the datetime.compare to compare the two:
If this works, let me know. I'm interested now.Code:System.DateTime date_dt = DateTime.Parse(SQL_str); System.DateTime dtNow=DateTime.Now; DateTime.Compare(dtNow,date_dt);
What I did was use the System.Datetime.Now and made that a string.
Then I concatenated that string into the select statement i was sending to the server.
I guess I didnt' realize that Datetime.Now was formatted like that, silly me.
After tinkering, I figured out that sql server actually has a built in date difference function, and a built in GetDateTime function... So now I can just have a simple select statement.
select someColumn from someTable where DATEDIFF(seconds,GETDATE(),someDate) > ElapsedTimeColumn
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks