Reputation: 17298
I want to change a value from int
or string
format to datetime
format. There is any function in SQL like the following?:
Function: Result TimeAdd( nextrundate,"sec",45) 00:00:45 TimeAdd( nextrundate,"min",45) 00:45:00 TimeAdd( nextrundate,"hour",4) 04:00:00 But: TimeAdd( nextrundate,"min",70) 01:10:00 TimeAdd( nextrundate,"min",190) 03:10:00
Is there a method that does this in C# also?
Upvotes: 1
Views: 556
Reputation: 3510
In SQL you could use something like
convert(varchar(8),dateadd(second,45,nextrundate),114) convert(varchar(8),dateadd(minute,45,nextrundate),114) convert(varchar(8),dateadd(hour,4,nextrundate),114)
Upvotes: 1
Reputation:
DateTime d = new DateTime();
d = d.AddMinutes(70);
Console.WriteLine(d.ToString("yyyy-MM-dd HH:mm:ss"));
Upvotes: 0
Reputation:
DateTime d = new DateTime(); d = d.AddMinutes(70); Console.WriteLine(d.ToString("yyyy-MM-dd HH:mm:ss"));
Upvotes: 0
Reputation: 6167
In C# you can use the DateTime and TimeSpan classes.
DateTime rundate = DateTime.Now();
DateTime nextRunDate= rundate .AddDays(1);
TimeSpan oneDay=(TimeSpan)(nextRunDate-rundate);
There are similar methods for minutes, seconds etc.
Upvotes: 0
Reputation: 29352
System.TimeSpan s = new TimeSpan();
s.Add(new TimeSpan(days, hours, minutes, seconds, milliseconds))
Upvotes: 2
Reputation: 19800
You mean:
see MSDN: http://msdn.microsoft.com/en-us/library/system.timespan_members(VS.80).aspx
Upvotes: 7