Datetime problems between c# and sql

I'm currently working on an SQL DB where one of the fields(Start_Time) in my shift table is a datetime datatype.

When I bind the values in my Start_Time field to a combobox in my front end it retrieves the values in the following format :   2006/03/22 03:40:21 PM

However if I run a normal select * query on my Shift Table  the same value as above is returned in the following format :  2006-03-22 15:40:21.000

What I'm trying to do is to use the selectd value in my combobox as a parameter in my storedprocedures but I am getting the [ 2006/03/22 03:40:21 PM]
value and not the [2006-03-22 15:40:21.000 ] value that my DB requires ! Please help!!
It`s driving me nuts!!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
see here for how to use parameterized queries (including datetime) which is the best way:
ChardiPAuthor Commented:
Hi Thanks for the response but my problem is not the stored procedure .
The problem is that the field returns two different types of formats for my datetime field
when you write your date in the combobox it becomes a DateTime,
you can just set the format of the DateTime

here is the msdn example on formats for DateTime:

DateTime july28 = new DateTime(1979, 7, 28, 5, 23, 15, 16);

string[] july28Formats = july28.GetDateTimeFormats();

// Print out july28 in all DateTime formats using the
// default culture.
foreach (string format in july28Formats) {

IFormatProvider culture =
    new System.Globalization.CultureInfo("fr-FR", true);
// Get the short date formats using the "fr-FR" culture.
string [] frenchJuly28Formats =
            july28.GetDateTimeFormats('d', culture);

// Print out july28 in various formats using "fr-FR" culture.
System.Console.WriteLine("Starting fr-FR formats");
foreach (string format in frenchJuly28Formats) {

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

You can also use DateTime.ParseExact to parse your datetime.

The thing is that when you run the select query on your table, you are only seeing the string representation of the value. As dkloeck says, you need to take it from a string value into a datetime, and pass a datetime into your stored procedure to ensure that you get the correct comparison.

If your C# is sending the data to the stored procedure using the DateTime parameter and then the stored procedure is accepting it as a DateTime, then it should convert between the two.  I have not had problems with this.

However, you could always format your date into the parts as shown by dkloeck or into a string and then do a cast and convert in SQL to ensure consistent formatting.
I think a split between these three comments:
dkloeck & AGBrown & mrichmon
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.