I have an application that displays data based on values in a table, so for instance I may have a date field in a particular table that needs to be formatted in a certain way (YYYY-MM-DD, etc). I have all the layouts and formats in a table but I need to be able to dynamically apply them at run time. So here's an example:
The data that I'm trying to display is 08/04/09 but I need to format it as the user sees fit, so it could be 2009-08-04, or 04-08-2009, or 04-08-09, etc. I have the code I need to do the formatting but cannot figure out how to apply it at runtime.
I've searched online and have only found how to apply a format to currency, numbers, date time. Nothing on how to manipulate a string using String.Format().
This is just an example of one particular field, the formatting can occur on any field at any time and it could be any format. So currency, or date time, number, left(), right(), etc...) So i need to be able to apply any of those formats at runtime.
I've attached a code snippet below so you can get an idea of what I'm trying to do.
I know the syntax is VB.Net, but a C# response would be fine as well.
Thanks in advance.
' Original value.
Dim tmp As String = "08/14/09"
' New formatted value.
Dim tmp1 As String
' This data would be retreived out of a database table.
' Trying to format the data as YYYY-MM-DD
Dim fmt As String = """20"" & tmp_input.Substring(7,2) & ""-"" & tmp_input.Substring(1,2) & ""-"" & tmp_input.Substring(4,2)"
' Save the results of the original data with the format applied.
tmp1 = String.Format(fmt, tmp)