Convert System.Date Time to Mysql

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
 
C

Cor Ligthert[MVP]

Amp,

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

Cor
 
I

Ignacio Machin ( .NET/ C# MVP )

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?
 
J

Jeff Johnson

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.
 
A

Arne Vajhøj

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top