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

I will explain my issue with the help of problem in one report.im using visual studio 2010 and sql server 2008 .In my development system i retrieve the details from database with in a date its working well .In text box im displaying date in dd/mm/yy format
C#
ld_fromdate = Convert.ToDateTime(como.ff_SetDate(txtcreatedfromdate.Text));
public string ff_SetDate(string datetime)
    {
            string[] date = datetime.Split('/');
            string DD = date[0];
            string MM = date[1];
            string YY = date[2];
            string dt = DD +"/"+ MM +"/"+ YY;
            return (dt);
       
    }

when i add this to server its not working instead the below code of conversion is working
C#
public string ff_mm_dd_yy_Date(string strDate)
       {
               string DD, Mm, Yy;
               string[] str = strDate.Split('/');
               DD = str[0];
               Mm = str[1];
               Yy = str[2];
               return ("" + Mm +"/"+ DD +"/"+ Yy + "";);
       }

first one working in development environment secon one working in server.as many other applications hosted in server i cant change system settings .how can i maintain through coding
Thanks in Advance
Amritha
Posted
Updated 21-Nov-12 21:12pm
v2
Comments
__TR__ 22-Nov-12 3:16am    
You can format date in SQL or in C#. Check the below links
How to format datetime & date in Sql Server[^]
C# DateTime Format[^]

1 solution

Your problem is probably that the server is set to a different locale to your development machine.

If you dev machine is set to European dates DD/MM/YY and your server is set to US dates MM/DD/YY then you will get this effect because the Convert.ToDateTime method uses the current locale to decide how to evaluate the date.

Use the DateTime.TryParseExact[^] method instead - you can specify the date format exactly that way.
 
Share this answer
 
Comments
amritha444 22-Nov-12 6:11am    
Thank you Griff datetime.tryparseexact concept helped to resolve my problem now its working in both development production system
OriginalGriff 22-Nov-12 6:15am    
You're welcome!

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