How to convert datetime HH:DD:SS AM/PM to HH:DD AM/PM

RMN picture RMN · Mar 1, 2012 · Viewed 14.1k times · Source

I have a gridview column, where I need to display time in format : 3/2/2012 1:22 PM

but my Db saves as 3/2/2012 1:22:42 PM

I want to remove seconds from this text. I can remove it using (MM/DD/YYYY HH:MM:SS) but how do i include the AM/PM from db column ?

Answer

Andre Loker picture Andre Loker · Mar 1, 2012

If the database provides the date as a DateTime, try to set the DataFormatString property of the GridView column to match your needs. For example

{0:MM/dd/yyyy hh:mm tt}

prints the column like 03/01/2012 03:09 PM .