This blog is dedicated to new technologies of Microsoft, including LINQ, sharepoint, ADO.NET entity framework and lot more
add
Showing posts with label DateTime. Show all posts
Showing posts with label DateTime. Show all posts
Tuesday, November 1, 2011
Convert DATETIME TO TIMESPAN IN C#
In the previous post, I mentioned how to convert DATETIME to TIMESPAN.
Now if the requirement is to convert DATETIME TO TIMESPAN, we can do that in one line:
DateTime dt="XXX";
TimeSpan TS = new TimeSpan(dt.Now.Ticks);
This will convert the DateTime to TimeSPan.
Varun
Convert TimeSpan To DateTime in c# + One line Code
We usually fall into the situation where conversion of Timespan to DateTime is required.
Here is how it can be done easily just by casting:
Suppose we have two variables DateTime and Timespan and Timespan one with some value
DateTime dt;
TimeSpan ts="XXX";
We can covnert 'ts' to 'dt' like this:
dt= Convert.ToDateTime(ts.ToString());
Thats it!!!
Hope you have liked the solution.
Varun
Here is how it can be done easily just by casting:
Suppose we have two variables DateTime and Timespan and Timespan one with some value
DateTime dt;
TimeSpan ts="XXX";
We can covnert 'ts' to 'dt' like this:
dt= Convert.ToDateTime(ts.ToString());
Thats it!!!
Hope you have liked the solution.
Varun
Subscribe to:
Posts (Atom)