axapta said:
Hi,
I have the following however the date is returned in the long format.
That's most likely not a completely accurate description of what's
happening.
If the field is a datetime field in the database, it's not returned as a
formatted string, it's returned as a DateTime value. That means that the
actual formatting is done when you assign the value to the text property.
I
want to display as dd/mm/yyyy.
If Not drReader.Item("offerstatusdate") Is DBNull.Value Then
txtOfferStatusDate.Text = drReader.Item("offerstatusdate")
End If
Instead of reading the value as an Object and implicitly converting the
DateTime value into a string, read the value as a DateTime value, and
explicitly format it the way that you want it:
txtOfferStatusDate.Text =
drReader.GetDateTime(drReader.GetOrdinal("offerstatusdate")).ToShortDateString()
or
txtOfferStatusDate.Text =
drReader.GetDateTime(drReader.GetOrdinal("offerstatusdate")).ToString("d")
or
txtOfferStatusDate.Text =
drReader.GetDateTime(drReader.GetOrdinal("offerstatusdate")).ToString("dd/MM/yyyy")
Note:
If you are doing this in a loop, you can call GetOrdinal outside the
loop and store the index of the field in an Integer variable.