DateTime string formatting for Oracle db?

  • Thread starter Thread starter sherifffruitfly
  • Start date Start date
S

sherifffruitfly

Hi,

God I hate datetime string formatting...

How do I get a string of the form "04-Oct-2006", for example, from a
DateTime object?

Thanks a jillion,

cdj
 
Hello sherifffruitfly,

Console.WriteLine(DateTime.Now.ToString("dd-MMM-yy"));

s> Hi,
s>
s> God I hate datetime string formatting...
s>
s> How do I get a string of the form "04-Oct-2006", for example, from a
s> DateTime object?
s>
s> Thanks a jillion,
s>
s> cdj
s>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Wilfried said:
Hi,

date.ToString("dd-MMM-yyyy");

dammit all to hell - I coulda SWORN I tried that and it didn't work.
lol!

Guess I didn't - thanks!

cdj
 
sherifffruitfly said:
God I hate datetime string formatting...

How do I get a string of the form "04-Oct-2006", for example, from a
DateTime object?

From your subject line, it *sounds* like you're trying to write a SQL
statement with the literal value in it. It's a *much* better idea to
use a parameterised SQL statement so that you don't need to do
formatting, escaping etc.
 
Jon said:
From your subject line, it *sounds* like you're trying to write a SQL
statement with the literal value in it. It's a *much* better idea to
use a parameterised SQL statement so that you don't need to do
formatting, escaping etc.

That sounds lovely. If only I knew what it meant - lol!

I'm using the Oracle .net data provider ado.net stuff. It seems
perfectly happy translating DataSet-string-dates into bonafide
Oracle-date-dates, so where's the harm?

If you'll give me detail about the approach you're talking about, I'm
more than happy to give it a whirl....

Thanks for the idea,

cdj
 
sherifffruitfly said:
That sounds lovely. If only I knew what it meant - lol!

I'm using the Oracle .net data provider ado.net stuff. It seems
perfectly happy translating DataSet-string-dates into bonafide
Oracle-date-dates, so where's the harm?

a) It means you need to get it right
b) It makes your code harder to port to other providers
c) If you do the same thing with other data types (and particularly
strings) you leave yourself open to SQL injection attacks if you're not
careful
If you'll give me detail about the approach you're talking about, I'm
more than happy to give it a whirl....

See http://www.pobox.com/~skeet/csharp/faq/#db.parameters
If that doesn't help, I'm sure the ADO.NET newsgroup will be happy to
provide more details :)
 

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

Back
Top