Declaring a variable that is a datetime datatype

N

.Net Sports

I'm trying to initialize a variable inside a PageLoad in
visualstudio.net :

mytoday = DateTime.Now;

...and the error (or Build Task error) says : The name 'mytoday' does
not exist in the class or namespace 'myProject.myfilename'

when i try :
datetime mytoday = DateTime.Now;
I get an error : the type or namespace datetime cant be found

when doing:
string mytoday = DateTime.Now;
or:
int mytoday = DateTime.Now;
I get an error : cannot be implicitly convert System.DateTime to
string

????
..Net Sports
 
M

Mythran

.Net Sports said:
I'm trying to initialize a variable inside a PageLoad in
visualstudio.net :

mytoday = DateTime.Now;

..and the error (or Build Task error) says : The name 'mytoday' does
not exist in the class or namespace 'myProject.myfilename'

when i try :
datetime mytoday = DateTime.Now;
I get an error : the type or namespace datetime cant be found

when doing:
string mytoday = DateTime.Now;
or:
int mytoday = DateTime.Now;
I get an error : cannot be implicitly convert System.DateTime to
string

????
.Net Sports

Try:

DateTime myToday = DateTime.Now;
- or -
string myToday = DateTime.Now.ToString();


hth :)

Mythran
 
M

Michael S

.Net Sports said:
I'm trying to initialize a variable inside a PageLoad in
visualstudio.net :

mytoday = DateTime.Now;

..and the error (or Build Task error) says : The name 'mytoday' does
not exist in the class or namespace 'myProject.myfilename'

when i try :
datetime mytoday = DateTime.Now;
I get an error : the type or namespace datetime cant be found

when doing:
string mytoday = DateTime.Now;
or:
int mytoday = DateTime.Now;
I get an error : cannot be implicitly convert System.DateTime to
string

????
.Net Sports


Seriously!

I'm not trying to be a complete bitch here, but you do need to hear this:

If your code above is problematic for you then you are not ready to code in
..NET. And especially not in C#.
You need to get some basic skills in OO and .NET. I would start with some
books and find tutorials on the web.

Oh, C# is case-sensitive. Did you miss that fundamental part of the
language?

Then again, I don't want to be too cynic. Keep on mastering C#. Coding adds
an extra dimension to your life. =)

Happy Learning
- Michael S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top