PC Review


Reply
Thread Tools Rate Thread

Convert System.Date Time to Mysql

 
 
AMP
Guest
Posts: n/a
 
      28th Apr 2009
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
 
Reply With Quote
 
 
 
 
Peter Morris
Guest
Posts: n/a
 
      28th Apr 2009
Don't parse it yourself, use query parameters!



--
Pete
====
http://mrpmorris.blogspot.com
http://www.AlterEgos.com - Who do you want to be?

 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      28th Apr 2009
Amp,

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

Cor

"AMP" <(E-Mail Removed)> wrote in message
news:c60a7416-26a6-4d03-9ecc-(E-Mail Removed)...
> 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


 
Reply With Quote
 
Ignacio Machin ( .NET/ C# MVP )
Guest
Posts: n/a
 
      28th Apr 2009
On Apr 28, 12:41*pm, AMP <ampel...@gmail.com> wrote:
> 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?
 
Reply With Quote
 
Jeff Johnson
Guest
Posts: n/a
 
      28th Apr 2009
"AMP" <(E-Mail Removed)> wrote in message
news:c60a7416-26a6-4d03-9ecc-(E-Mail Removed)...

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


 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      3rd May 2009
Jeff Johnson wrote:
> "AMP" <(E-Mail Removed)> wrote in message
> news:c60a7416-26a6-4d03-9ecc-(E-Mail Removed)...
>> 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.


MySQL classes are prefixed with MySql.

And parameteres are prefixed with ? instead of @.

But besides that it is just like SQLServer.

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert military date system to standard date system John Weaver Microsoft Excel Misc 8 17th Sep 2009 06:12 PM
Convert unix time to date/time in Access 2003 for a linked tabel Kevin Joyce Microsoft Access Getting Started 5 7th Oct 2008 08:18 PM
Convert date to length of time in months from set date =?Utf-8?B?TUpVSw==?= Microsoft Excel Worksheet Functions 1 19th Mar 2005 06:31 PM
Convert Date Time in Spreadsheet Column to Date only Genga Microsoft Excel Programming 1 8th Jun 2004 08:18 PM
Date/Time Calculations in MS Access 2002 using a MySQL backend bluerocket Microsoft Access External Data 1 5th Feb 2004 03:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:18 AM.