Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Hi,

My Date Format is 27/10/2015..

DateTime dtt = ObjRaiseDTO.Date;

Here I am getting "1/1/0001 12:00:00 AM"

Then it shows an error ..How can i convert this.. Please help me
Posted
Updated 27-Oct-15 0:46am
v3
Comments
Ralf Meier 27-Oct-15 7:01am    
I'm not sure what you try to achieve.
Do you want to catch the Error-Message ?
Or do you want to add this Datevalue to a specified Date-Offset ?
SHIVA1434 27-Oct-15 7:04am    
I want to save datetime in my DB , I got an error like ..
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM

But I gave 27/10/2015 date
..If I give 10/27/2015 ..Then their is no problem
[no name] 27-Oct-15 7:24am    
As per your comment "If I give 10/27/2015 ..Then their is no problem" you should use that form format "mm/dd/yyyy"
Suvendu Shekhar Giri 27-Oct-15 7:29am    
While sending to DB send with correct or neutralized format.
May be something like - dtt.ToString("yyyy-MM-dd HH:mm:ss")

1 solution

Try this
DateTime Result = DateTime.ParseExact("27/10/2015", "dd/MM/yyyy", CultureInfo.InvariantCulture);


https://msdn.microsoft.com/en-us/library/w2sa9yss(v=vs.110).aspx[^]

Regards..
 
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