Solved

asp.net formatting military time

Posted on 2004-08-23
12
645 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now