Convert System.Date Time to Mysql

  • Thread starter Thread starter AMP
  • Start date Start date
A

AMP

Hello,
I am trying to convert a System.DateTime to a mysql Date time.
This is what I get:
4/28/2009 12:28:22 PM

and this is what I want
2009-04-28 12:28:22

I cant seem to do it successfully.
Any help?
Thanks
 
Amp,

You can always use the overloaded ToString from the DateTime
string x = myDate.ToString("yyyy-MM-dd dd:mm:ss");

Cor
 
Hello,
I am trying to convert a System.DateTime  to a mysql Date time.
This is what I get:
4/28/2009 12:28:22 PM

and this is what I want
2009-04-28 12:28:22

I cant seem to do it successfully.
Any help?
Thanks

Hi,

Those are string representations of a DateTime , I'm pretty sure that
the provider for MySql can do the conversion of a .NET DateTime to
whatever MySql use.

What is the code you are using anyway?
 
I am trying to convert a System.DateTime to a mysql Date time.
This is what I get:
4/28/2009 12:28:22 PM

and this is what I want
2009-04-28 12:28:22

I cant seem to do it successfully.

Nor do you need to.

Nor should you even try.

The very fact that you're asking this question suggests (and virtually
screams) that you're building SQL strings dynamically. This is a
monumentally bad idea. Use xxxCommand objects (I don't use MySQL so I don't
know exactly what they're called) and parameters. Then you'll never have to
worry about the proper representation of any data value in the underlying
SQL; the Command object will take care of that for you.
 
Jeff said:
Nor do you need to.

Nor should you even try.

The very fact that you're asking this question suggests (and virtually
screams) that you're building SQL strings dynamically. This is a
monumentally bad idea. Use xxxCommand objects (I don't use MySQL so I don't
know exactly what they're called) and parameters. Then you'll never have to
worry about the proper representation of any data value in the underlying
SQL; the Command object will take care of that for you.

MySQL classes are prefixed with MySql.

And parameteres are prefixed with ? instead of @.

But besides that it is just like SQLServer.

Arne
 
Back
Top