Click here to Skip to main content
15,905,776 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wanted to concate date and time. Here is my code.
C#
string dateOfCheckOut = lblDateData.InnerText;
DateTime dateofCheckOut = Convert.ToDateTime(dateOfCheckOut);
string date = dateofCheckOut.ToString("MM/dd/yyyy");

endTimeOfAttendance = configSetting.EndTimeOfAttendance.ToString("HH:mm:ss");

DateTime dateTimeOfCheckout = DateTime.Parse(dateOfCheckOut + " " + endTimeOfAttendance);


here data will come from lblDateData and time will come from endTimeOfAttendance which is extracted from time stored in table which is 2014-05-02 17:30:00.000 .. i wanted date to be of lblDateData but time to be 17:30:00.000. here as i concate,dateTimeOfCheckout will show value as i wanted in localhost say if date is 2014-05-05, dateTimeOfCheckoutill be 2014-05-05 17:30:00.000 but as it is published in IIS the dateTimeOfCheckout value will be 2014-05-05 00:00:00.000

Is there something that is required.. can anyone tell how to correct it?? thanks in advance
Posted
Updated 5-May-14 21:03pm
v2

What about
C#
DateTime dateTimeOfCheckout = new DateTime(dateofCheckOut.Year, dateofCheckOut.Month, dateofCheckOut.Day, configSetting.EndTimeOfAttendance.Hour, configSetting.EndTimeOfAttendance.Minute, configSetting.EndTimeOfAttendance.Second);
 
Share this answer
 
try this one......

string dateOfCheckOut = lblDateData.InnerText;

string dateandtime =dateOfCheckOut +" "+endTimeOfAttendance ;

DateTime dateTimeOfCheckout = DateTime.ParseExact (dateandtime ,"dd/MM/yyyy hh:mm:ss tt" ,CultureInfo.InvariantCulture );


change the format according to your way
 
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