Groups | Blog | Home
all groups > asp.net datagrid control > march 2006 >

asp.net datagrid control : Format Time in DataGrid


crjunk NO[at]SPAM earthlink.net
3/22/2006 11:54:11 AM
I'm working with a table that has a field that stores time values as a
string. The time values are in military time (such as 13:30).

How can I have 13:30 displayed as 01:30 PM in my datagrid? Can I use
DataFormatString to achieve this?

Thanks,
CR Junk
Elton Wang
3/22/2006 9:39:21 PM
Try

DataFormatString ={0: HH:mm tt}
or
DataFormatString ={0: hh:mm tt}

HTH

[quoted text, click to view]

crjunk NO[at]SPAM earthlink.net
3/23/2006 6:42:15 AM

[quoted text, click to view]

Hi Elton,

I tried using both of your suggestions, but they seem to have no effect
on the formatting of the data in the datagrid. Any other suggestions?

Thanks,
CR Junk
crjunk NO[at]SPAM earthlink.net
3/23/2006 12:19:49 PM
Hi Elton,

I forgot to modify my SQL statement:
SELECT CAST(MyTime as DateTime) as MyTime from MyTable.

After adding the Cast/DateTime statement to the MyTime, the
DataFormatString ={0: hh:mm tt} worked when added to the datagrid.

Thanks again!
CR Junk
Elton Wang
3/23/2006 10:35:26 PM
It should be

DataFormatString="{0: hh:mm tt}"

[quoted text, click to view]

AddThis Social Bookmark Button