Currently, I’m populating a DropDown with the following SQL:
SELECT REPORT_DATE FROM MY_TABLE
Although the values stored in the table are in the following format, dd-mon-yyyy (my preferred format), the text that fills my DropDown differs in that it also displays time, like dd-mon-yyyy hh:mm:ss AM.
What is the best way to resolve this? I know of TRUNC and TO_DATE functions in Oracle SQL. But I think I could also loop through the DropDown after its populated and truncate the string there. I have tried the following code, but it returns a runtime error:
For Each i As ListItem In DropDown1.Items
'Strip time here
i.Text.ToString("dd-MMM-yyyy")
Next
Essentially, I just want to loop my DropDown and change ONLY the text to match `dd-MMM-yyyy’. How can I accomplish this? Should I use SQL or VB.NET? Is there a best practice?
Thank you!
If the data is of type DateTime, you can simply specify the DataTextFormatString property on the dropdown as so:
It should be to the UI layer to display the date in the format you want. You should try to avoid putting the logic to transform the date to the format you want on the SQL statement, if possible.