How to format the time field?

  • Thread starter Thread starter Miguel Dias Moura
  • Start date Start date
M

Miguel Dias Moura

Hello,

in an ASP.net page i have the following lines:

Dim Time As DateTime = Ctype(row("Time"),DateTime)
strEvents.Append("<br>" + Time + "-" + row("Event"))

In my access database the time is with the following format: hh:mm (It
doesn't include the seconds)

However, when i show strEvents the time shows like this: 12:30:00

How can i take out the seconds and display only the hours and minutes?

Thank You,
Miguel

P.S: I get the same result when i use the follwing code:
strEvents.Append("<br>" + row(Time) + "-" + row("Event"))
 
Use the DateTime.ToString method with the desired format specifier. It 'll
take care of both formatting the date based on your current national
settings. Will be also a good help if you need later to support several
display languages...
 
I am not familiar with it. Can you help me out and tell me how should i use
it?

Thanks,
Miguel
 
Basically it should be :

CType(row("time"),DateTime).ToString("d")

See
http://msdn.microsoft.com/library/d...ml/frlrfSystemDateTimeClassToStringTopic3.asp
for other format specifiers.

Also for language dependant formats, it uses the language that you can set
in web.config (ie. the example above will render as "JJ/MM/AAAA" in French
but "MM/JJ/AAAA" in US english).

If you want to support a single language, the easiest is to set it in the
web.config file :
http://msdn.microsoft.com/library/d...s/cpgenref/html/gngrfglobalizationsection.asp

Patrice
 

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