Hello, Im using a MonthCalender to get a dateTime, and just a textbox to let the user enter hours and minutes, so now I just want to add this so say the user enters 10:20 then I would like it to be (for example) 1999-10-10 10:20:00 instead of 1999-10-10 00:00:00, so I tryed to convert the string 10 to a double and the string 20 to an other double and trying to use dateTime.addhour(hours); But this wont work, the datetime is still 1999-10-10 00:00:00... I dont have my code on this computer, if you dont get what I mean i can post it, but we can start with this
Here is the code now too!!
startHour is 10:00:00 if you enter 10 hours, but i still get 1999-10-10 00:00:00Code:DateTime dtStart, dtEnd; TimeSpan startHour, startMin, endHour, endMin; dtStart = this.mcStartDate.SelectionStart; dtEnd = this.mcEndDate.SelectionStart; startHour = TimeSpan.FromHours(Convert.ToDouble(this.mtbStartTime.Text.Substring(0,2))); dtStart = dtStart.Add(startHour);
/Nick
Last edited by nick3; 01-19-2010 at 08:06 AM.
DateTime object is not mutable. When you use AddHours() method it returns new DateTime object.
Code:using System; namespace ConsoleApplication1 { class Program { static void Main() { var date = DateTime.Today; date = date.AddHours(10); Console.WriteLine(date); Console.ReadLine(); } } }
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks