bidgadget
asked on
Format date label field in Visual Studio and VB.net
Visual Studio 2015 using vb.net I have a label that is displaying a date field from a database. On the form the date shows up as Nov 20 2018 and I need it to show up as November 20, 2018
Is there a way to format the field to show the correct date format?
Is there a way to format the field to show the correct date format?
What is your current code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you. That worked
ASKER
Actually I am trying to get the date value in the database files. Your solution is giving current date.
How would I get the current data entered in the field in that format? Thank you
How would I get the current data entered in the field in that format? Thank you
A database should always store a date in a date/datetime format. In order to save a date using a very specific format, you would to store it as a string and you really don't want that.
Once a value is stored into the database, it belongs to the client app/reporting to format it the way you really it
Once a value is stored into the database, it belongs to the client app/reporting to format it the way you really it
ASKER
So there is no way then to create another label field and take the date in the database and format it the way I want?
where are you trying to show that date?
ASKER
On a letter that will pull the date entered into the database field. I am able to get it to show for example Oct 30 2018 but I need it to show October 30, 2018
How do you produce that letter? If you pass the value from your application to the letter, you can use the same syntax:
or if you letter is produced using a reporting engine, there is surely a field format feature
yourobjectonyourletter = yourfieldfromthedatabase.ToString("MMMM d, yyyy")
or if you letter is produced using a reporting engine, there is surely a field format feature
ASKER
Just producing the letter off a form in asp.net in visual studio
That doesn't tell me what kind of object you are trying to feed. I really want to help you but you also need to help me.
ASKER
so sorry.
I have a sql database table. I have a field called confirm_date_instructed. It is a datetime field.
I have a form that I am using as a letter. The sentence is. "your date instructed of _______ The __________ is supposed to be the database filed of Confirm_date_instrcted. The contents of the field are entered as a date in the process before this field. I want the field to show up as a full date. For example if the date was entered in the prior form and submitted to the database was 10/30/2018, I would want it to show as October, 30, 2018
I have unprotected the field by using
Dim CONFIRM_DATE_instructed As Label = CType(FormView1.FindContro l("CONFIRM _DATE_inst ructedLabe l"), Label)
then I want to convert the field
CONFIRM_DATE_instructed.Te xt = CONFIRM_DATE_instructed.To String("MM MM d, yyyy")
I am getting the error
An exception of type 'System.InvalidCastExcepti on' occurred in Microsoft.VisualBasic.dll but was not handled in user code
Additional information: Conversion from string "MMMM d, yyyy" to type 'Integer' is not valid.
I have a sql database table. I have a field called confirm_date_instructed. It is a datetime field.
I have a form that I am using as a letter. The sentence is. "your date instructed of _______ The __________ is supposed to be the database filed of Confirm_date_instrcted. The contents of the field are entered as a date in the process before this field. I want the field to show up as a full date. For example if the date was entered in the prior form and submitted to the database was 10/30/2018, I would want it to show as October, 30, 2018
I have unprotected the field by using
Dim CONFIRM_DATE_instructed As Label = CType(FormView1.FindContro
then I want to convert the field
CONFIRM_DATE_instructed.Te
I am getting the error
An exception of type 'System.InvalidCastExcepti
Additional information: Conversion from string "MMMM d, yyyy" to type 'Integer' is not valid.
Hum!!!! You have that full sentence in the label and you want to extract the date?
Because in your code, you are saying CONFIRM_DATE_instructed = CONFIRM_DATE_instructed. This is not logical!
Because in your code, you are saying CONFIRM_DATE_instructed = CONFIRM_DATE_instructed. This is not logical!
ASKER
Sorry. That was just a trial. Not sure how I would do it
what do you have in your CONFIRM_DATE_instructedLab el.Text? In which object (dataset or other) is your datetime field?
ASKER
the Datetime field is the Confirm_date_instructed which is part of the dataset.
The below code hives me mm/dd/yyyy but need it to be full date ie october 30, 2018
CONFIRM_DATE_instructed.Te xt = CONFIRM_DATE_instructed.Te xt.Substri ng(0, CONFIRM_DATE.Text.Length - 7)
The below code hives me mm/dd/yyyy but need it to be full date ie october 30, 2018
CONFIRM_DATE_instructed.Te
it would be much safer to go back to the dataset :
CONFIRM_DATE_instructed.Text =directcast( yourdataset.tables(yourtableid).rows(yourrowid).item("yourfieldname"), datetime).ToString("MMMM d, yyyy")