Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi ,,
i want to get Date from DateTime class Properties ,, but its give me a wrong answer

C#
DateTime d=new DateTime();
Response.Write(d.Date);


the answer is : 1/1/0001 12:00:00 AM !!!!

i need a little help ... tanQ's
Posted
Comments
Sergey Alexandrovich Kryukov 19-Nov-12 0:49am    
What happened? MSDN broken?!
--SA

datetime object.now will generate present date and time.
 
Share this answer
 
Once try this.

var now = new Date().toDateString();
 
Share this answer
 
Comments
mahmii 19-Nov-12 1:02am    
TanQ's
Yes it will return 1/1/0001 12:00:00 AM.

For current datetime use:

C#
DateTime d=DateTime.Now;
Response.Write(d.Date);
 
Share this answer
 
Comments
mahmii 19-Nov-12 1:02am    
TanQ's :)
Of course: this is exactly what you should have obtained. And what did you expect? Current time? This is DateTime.Now? Something else? Read http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

—SA
 
Share this answer
 
Comments
mahmii 19-Nov-12 1:02am    
TanQ's
Sergey Alexandrovich Kryukov 19-Nov-12 11:46am    
Sure.
Are you going to accept the answer formally then (green button)? -- thanks.
--SA

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