I have an asp.net webpage with a drop down menu that is populated by a databound list that pulls it’s entries (dates) from a database.
I have this part working and displaying the correct information, but the thing is that it displays the dates as mm/dd/yyyy hh:mm:ss AM/PM. Ideally, I would like it to display as mm/yyyy (even just mm/dd/yyyy would be ok).
Does anyone know how to do this?
Thanks.
The simplest approach is to do it in the Select statement – use the Convert() function (assuming the DB is SQL Server)
Usage and different formats (alternatives to “101” in the example above) can be found here: http://msdn.microsoft.com/en-us/library/ms187928.aspx
Alternately, you can use the DataTextFormatString property: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.datatextformatstring.aspx
and set it to “{0:dd/MM/yyyy}”