DateTime issues with a.m./p.m.

D

Doug Swanson

We have as ASP.NET application that hits a SQL Server database. When I
change the culture info from 'en-US' to 'es-MX' my code that queries the
database fails....I've set my dateform to dmy on the sqlserver side....my
sql code that goes up to the db looks like this...

select...
from x
where x.start_dt > '29/10/04 12:00:00 a.m.'

It chokes on the 'a.m.'....if I change the text to 'AM' then it is
fine....is there some thing I'm missing in my vb.net code? Basicly I'm
building the sqlstring on the fly

Dim sSQL as string
sSQl = "select .. from x where x.start_dt > '" + mydate.toString() + "'"

How do I force a 24 hour clock display?

thanks
Doug


--
Doug Swanson
Senior Applications Developer
Synchrono, Inc
651.228.1772
(e-mail address removed)
 
D

Doug&Cindy

SQL injection is a risk but we never just take what the user types in an
entry field and append that into SQL. We always place it in it's
appropriate type variable. So our datetime values always come from
mydate.toString(). My question is how do I get it to always display a 24hr
clock with no AM or a.m.?

thanks
Doug
 
H

Hayato Iriumi

Well, if that's the case, can't you use parameter for ToString method of
DateTime object to make get a.m., and p.m. This is a format issue now.

So...

Dim MyDate As DateTime = DateTime.Now

Debug.WriteLine(Mydate.ToString("mm/dd/yyyy HH:mm:ss")) or something
like that. When you hit F1 on ToString method of DateTime structure, you
will get a good help on how to format DateTime.
 

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