Click here to Skip to main content
15,944,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI All,

I need a small help.

i have two strings one for date and one for time i have concatenated them to get the datetime and after that i have used all the methods to convert my datetime string in datetime format but unfortunately that conversion is working in my local but when i made the release in uat environment then it is not working properly wat to do

so finally my datetime is working in local system but the same is code is not working in server machine wat to dooo...

var provider = CultureInfo.CurrentUICulture;
order1 = order.OrderDate + " " + order.OrderTime;
            delivery = order.DeliveryDate + " " + order.DeliveryTime;
            //order1 = string.Format("{0:dd-mm-yyyy HH:mm}", order1);
            //delivery = string.Format("{0:dd-mm-yyyy HH:mm}", delivery);
            string format = "yyyy-MM-dd HH:mm:ss";
            //DateTime.TryParseExact(order1,format,CultureInfo.InvariantCulture,DateTimeStyles.None, out o1);
            DateTime.TryParseExact(delivery,format,provider,DateTimeStyles.None, out d);
            //o1 = DateTime.ParseExact(order1, "yyyy-MM-dd HH:mm:ss", provider);
            //d = DateTime.ParseExact(delivery, "yyyy-MM-dd HH:mm:ss", provider);
            DateTime.TryParse(order1,out o1);
            d = DateTime.ParseExact(delivery, format, provider);
            item.orderDateTime = o1;
Updated 25-Aug-13 2:06am
[no name] 25-Aug-13 8:07am    
Well the very first thing you should is define what "not working" means.

string order1 = "2013-04-01 01:00:00 pm";
string delivery = "2013-04-02 02:00:00 pm";
DateTime d;
DateTime o1;
DateTime.TryParse(delivery, out d);
DateTime.TryParse(order1, out o1);
Console.WriteLine(d.ToString("yyyy-MM-dd HH:mm:ss"));
Console.WriteLine(o1.ToString("yyyy-MM-dd HH:mm:ss"));

Yields this result:
4/2/2013 2:00:00 PM
4/1/2013 1:00:00 PM
2013-04-02 14:00:00
2013-04-01 13:00:00
Share this answer

You can check with following DateTime constructure example --

System.Globalization.CultureInfo info =
    new System.Globalization.CultureInfo("en-US", false);

System.Globalization.Calendar calendar = info.Calendar;

System.DateTime dateTime = 
    new System.DateTime(1979,        // Year
                        07,            // Month
                        28,            // Day
                        22,            // Hour
                        35,            // Minute
                        5,            // Second
                        15,            // Millisecond
                        calendar    // Calendar
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