Click here to Skip to main content
15,902,814 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When I am trying this:
C#
string invMonth = (txtInvoiceEndDate.Text)DateTime.Now.GetDateTimeFormats()[130].Substring(0, 3);


I get an error "Text box is field but used like type". What am I doing wrong?
Posted
Updated 16-Nov-15 0:00am
v2
Comments
[no name] 16-Nov-15 5:53am    
What are you trying to do by this line of code ?

The field txtInvoiceEndDate.Text is not a Type. You cannot convert data into an instance or value directly.
You can cast to a type. Thus using Convert.ToString() will work.
string invMonth = Convert.ToString(DateTime.Now.GetDateTimeFormats()[130].Substring(0, 3));
 
Share this answer
 
Comments
Leo Chapiro 16-Nov-15 8:47am    
The OP don't need any cast IMHO, the return value of Substring is already a string!
This should return short month name:
C#
string invMonth = DateTime.Now.ToString("MMM");


You can additionally pass the culture you want it formatted for.
 
Share this answer
 
You have a Control named "txtInvoiceEndDate" (probably a TextBox) and this control has a field named "Text". Surely this is not the same as a string, BTW you don't need any cast here:
C#
string invMonth = DateTime.Now.GetDateTimeFormats()[130].Substring(0, 3);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900