Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
User will enter datetime in mm/dd/yyyy hh:mm:sec format because in my database i have time format in mm/dd/yyyy and i should also retrieve data from other database which is in dd/mm/yyyy with the same input datetime which is given before by the user. So i tried bellow logic.


DateTime dd1 = dt1;
DateTime dd2 = dt2;
string newdate1 = dd1.ToString("dd/mm/yyyy hh:mm:ss");
string newdate2 = dd2.ToString("dd/mm/yyyy hh:mm:ss");



but in mm it is taking random value i.e if user entered 06(month) but it is taking a random value other than 06 while converting.

i also tried in sql in different formats.

select top 1 receivedtime,stfuelpercent/10,(stfuellevel/100)*2.605 from m2m_raw_fuel where receivedtime between convert(nvarchar(50),'06/16/2013 10:43:00',102) and convert(nvarchar(50),'06/16/2013 14:09:00',102) order by receivedtime desc


the above query is also not converting mm/dd/yyyy to dd/mm/yyyy. so please help me.
Posted

1 solution

Please write months in capital letter. i.e.

C#
string newdate1 = dd1.ToString("dd/MM/yyyy hh:mm:ss");
string newdate2 = dd2.ToString("dd/MM/yyyy hh:mm:ss");
 
Share this answer
 
Comments
_Amy 17-Jun-13 3:30am    
+5!
saguptamca 17-Jun-13 4:23am    
:)

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