In Visual Basic, I have an object with an ItemDate key in it with the value being assigned to a label in ASPX. Here is the code:
lblItemDate.Text = .ItemDate
The result on the front end is ‘2021/11/15’. I want the result to be: ‘November 15, 2021’
What do I need to do in Visual Basic to make the result on the front end be ‘November 15, 2021’ instead of ‘2021/11/15’?
In another VB file, the ItemDate object key is created this way:
oItem.ItemDate = Trim(odbcReader("ItemDate").ToString)
2
Answers
Assuming you really have a .Net DateTime struct:
Otherwise you have a string, in which case you want to parse into a .Net DateTime struct so you can use the same ToString() call above:
Even better if you can update your code so
ItemDate
is a DateTime value in the first place, and theParse()
call is moved to the point where the object is first created.It’s been a while, so I don’t recall whether the
.ItemDate
shortcut is available in the context of a function call. You may need to use the full version of the variable name.Besides the .Net functions mentioned in another answer, which work across different languages, there is also the Format(..) function traditionally included with professional implementations of BASIC since the early 70’s (I first used it in DEC’s BASIC-Plus in 1976).
To get ‘November 15, 2021’ you’d do it like this: