is there a function that would do this
DateTime1.minute=50
if i add 10 minutes it would add 1 hour and set minute to 0 and likewise
is there a function that would do this
DateTime1.minute=50
if i add 10 minutes it would add 1 hour and set minute to 0 and likewise
You can add a TimeSpan
via .Add()
DateTime now = DateTime.Now;
TimeSpan tenMinutes = new TimeSpan(0, 10, 0);
now = now.Add(tenMinutes);
You can also AddDays(int days)
, AddHours(int hours)
, AddMinutes(int minutes)
,AddSeconds(int seconds)
, etc.
All of these functions return DateTime objects so you'll have to set the value equal to the return value of the method.
DateTime now = DateTime.Now;
now = now.AddMinutes(10);
If I understand your question, you can use the AddMinutes method if you just want to add minutes...
http://msdn.microsoft.com/en-us/library/system.datetime.addminutes.aspx
As Darin Dimitrov mentions, there is an AddMinutes function.
However, be aware that you can't just do:
dateTime1.AddMinutes(50);
AddMinutes
returns a new DateTime, so you'll need to do:
dateTime1 = dateTime1.AddMinutes(50);
Or a shorter code example
DateTime dt = DateTime.AddMinutes(50);
// some other logic here
dt.AddMinutes(10);
That should initially set it to 50mins and then adding another 10mins would make it an hour. You may want to consider using a TimeSpan instead though.
TimeSpan span = TimeSpan.FromMinutes(50);
span += TimeSpan.FromMinutes(10);
Console.WriteLine(span.Hours); // prints "1"