Solved

asp.net formatting military time

Posted on 2004-08-23
12
649 Views
Last Modified: 2012-06-21
I want to show short date 9/15/04 and military time 23:10

What would I do to convert this my TextTimeIn.Value to that format?

If Not row.IsTimeInNull Then Me.TextTimeIn.Value = row.TimeIn

Its' currently showing this: 8/21/2004 2:38:09 PM

0
Comment
Question by:jamesh1031
  • 5
  • 3
  • 2
  • +1
12 Comments
 

Author Comment

by:jamesh1031
ID: 11873362
This data is stored in one field (date and time) (MS Sql)
0
 
LVL 2

Assisted Solution

by:netjkus
netjkus earned 100 total points
ID: 11873425
string dtformat = "MM/dd/YYYY HH:mm:ss";

string Timenow = DateTime.Now.ToString(dtformat);

Note the Capital HH - makes it 24 hour format.

any question email me.
0
 
LVL 2

Expert Comment

by:netjkus
ID: 11873441
Or if you need to convert a datetime existing, eg.

 Datetime Dttest = GetdatetimefromDBfield();

dttest.ToString(dtformat);
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:jamesh1031
ID: 11873466
So, how do add it to the page?

If Not row.IsTimeInNull Then Me.TextTimeIn.Value = row.TimeIn
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11873594
Hi there,
use...
     If Not row.IsTimeInNull Then Me.TextTimeIn.Value = Format(CType(row.TimeIn , Date), "HH:mm")

-Baan
0
 
LVL 3

Expert Comment

by:gspronych
ID: 11887671
Hi

I found the easiest way to change date formats by changing the page culture.

Click the page, and scroll down to culture in the properties window.
Change the culture to this property for your formatting: en-GB English (United Kingdom)
This culture will shows dates in this format '24/08/2004 16:09:42'
Changing the culture will display times as described by each culture.

Localization can be done project wide, or page specific as I described above.
0
 

Author Comment

by:jamesh1031
ID: 11887902
I couldn't get dotnetlover's method to work....i don't have anywhere where I see "culture" in visual studio.net in a properties window..i may post the question at sql as I want to make sure that the display format won't mess up the db data when saving.
0
 
LVL 3

Accepted Solution

by:
gspronych earned 300 total points
ID: 11888110
To manually add a culture to a page, add the culture keyword to your page directive.
Click the html tab to view the html version of your page.

Then add this value at the top of the page
culture="en-GB"

My page directive looks like this

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="RTF.aspx.vb" Inherits="Secure.RTF" culture="en-GB"%>

It's worth a try


0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11888277
>> "I couldn't get dotnetlover's method to work"<<  
what is the error you are geting ?
0
 

Author Comment

by:jamesh1031
ID: 11888808
no error, just didn't format the date and time.

0
 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 100 total points
ID: 11889042
Hi there...
if you want to change your culture from code....

Imports System.Globalization
Imports System.Threading

Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")

Then use my earlier post...
visit this link...  http://www.microsoft.com/globaldev/getWR/steps/wrg_date.mspx
-Baan
0
 

Author Comment

by:jamesh1031
ID: 11889154
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question