frenchie
frenchie

Reputation: 51927

Gridview time format

I have a BoundField that's using a Datafield linked to a datetime type variable. I want to display only the time, not the date. How do you show the time in 24-hour format or in AM/PM format, depending on a boolean in the code behind.

Thanks.

Upvotes: 1

Views: 6709

Answers (1)

Remy
Remy

Reputation: 12693

Try something like this:

<%# Eval("AmPmMode").ToString().Equals("true")) ? 
String.Format("{0:hh}:{0:mm} {tt}", Eval("date")) : 
String.Format("{0:HH}:{0:mm}", Eval("date"))  %>

You can format your date for AM PM mode or for 24h mode. tt is the AM/PM designator. AmPmMode is flag from you DB, should be true or false, but you could change it to 0 or 1.

See also:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Upvotes: 4

Related Questions