Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Date comparison with C# and SQL Server 2005 (http://www.go4expert.com/forums/date-comparison-c-sharp-sql-server-2005-t5655/)

rhaazy 4Aug2007 01:48

Date comparison with C# and SQL Server 2005
 
In C# code I want to do a date comparison against a column is the database.

Something like:

select someColumn from someTable
where CurrentDate-someDate > ElapsedTimeColumn

I want to get the currentdate in C# and run a query from my application.

How do i get the format of:

mm/dd/yyyy hh:ss:mm AM/PM

Thanks.

shabbir 4Aug2007 12:41

Re: Date comparison with C# and SQL Server 2005
 
DateTime class located in the System namespace would help you.

Code:

System.DateTime.Now

System.DateTime.Today


rhaazy 7Aug2007 19:19

Re: Date comparison with C# and SQL Server 2005
 
Any idea what system.datetime.now would throw an sql exception error?
The format it returns is identical to the format of my sql column....

This isn't an issue, and I decided to just use the sql function getdate to do what I needed, but I do no understand why this would throw an error. Perhaps it is a simple formatting error on my part when concatenating the strings, but maybe someone had a similiar problem before. thanks.

SNK111 1Jun2010 22:04

Re: Date comparison with C# and SQL Server 2005
 
This scenario usually arises when the data is not 'received' properly from the database.

Check this link ( shahriarnk.com/Shahriar-N-K-Research-Embedding-SQL-in-C-Sharp-Java.html ) for details on how to connect to SQL Server database from C#.NET database applications as well as Java database applications. It also describes how to pass embedded SQL queries, calling stored procedures, pass parameters etc.

Shahriar Nour Khondokar: shahriarnk.com/


All times are GMT +5.5. The time now is 20:58.