Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong with this? 1

Status
Not open for further replies.

andybeeeeee

Programmer
Dec 9, 2002
17
GB
I'm writing some code and i have the following line:

Code:
oppty.CloseDate = 23/09/2004;

When i try to build it, there is an error that this isnt in the right format: Cannot implicitly convert type 'int' to 'System.DateTime'

what's the right syntax for me to enter this in so that it recognises it as a date, rather than an integer?
 
you can use
optty.CloseDate = new DateTime(2004,09,23);

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
just out of interest, does that make the date represented in us format (mm/dd/yyyy) or uk (dd/mm/yyyy)? i need it to be displayed in uk format, and there's an error with this line of code when i run the program and i have a feeling its to do with the format
 
it has nothing to do with the way it gets displayed. to display a date you use a ToString() or an alternative: ToShortDate, ToLongDate...

in the ToString method you can specify which format to apply and from here you can specify the regional settings of your computer (I don't know if this is the implicit setting or not)

what error do you get?
it's probably because the date entered is not valid (e.g. the month specified doesn't have that many days... etc)

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
when i said displayed, i meant stored ;) my bad!

basically this piece of code connects to a database online and the closedate is one of the attributes thats passed to the database. Even though it's in the code, i get a runtime error saying that it needs to be present (its a required field). I'm not 100% sure, but i reckon its the format of the data
 
dont worry, ive cracked it now. all is well.

thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top