Postgre Date Formatting

I am trying to read a date field in postgre ‘yyyy-mm-dd’ and want to display it as ‘dd-mm-yyyy’ in a combobox for selection. I’m not sure of the best way to reformat the date and then back again after it is selected.

Use Date.ShortDate to display it, but keep the SQL format in the rowtag so you don’t have to parse it back.

This is the code I am trying to apply what you suggested

Dim date as Date While Not rs.EOF date = rs.Field("woods_swedm").DateValue swedm = str(date.ShortDate) +" | " + Format(rs.Field("pct_comp").Value,"###") + "%" ComboBox1.AddRow(swedm) ComboBox1.RowTag(ComboBox1.ListIndex) = rs.Field("woods_swedm").StringValue rs.MoveNext Wend

 Where am I going wrong. I get an error.

Change ComboBox1.ListIndex to ComboBox1.ListCount -1. Listindex hasn’t been set yet.

ListIndex is to get or set the currently selected item. As Wayne said, ListCount - 1 is what you want. Better yet, create an extension method for ComboBox that is LastIndex so that it can be used just like ListBox.

You also do not need the str(date.ShortDate) - just use date.ShortDate as it is a string property of date.