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
4 comments:
Extrapolating from the above suggestion, wouldn't this work:
Dim dtStartTime as new DateTime
Dim tsStartTime As TimeSpan = New TimeSpan(dtStartTime.Hour, dtStartTime.Minute, dtStartTime.Second)
Since TimeSpan takes hours, minutes, and seconds as arguments.
Nice blog.. Thanks for sharing this blog information with us…
This does not work. Now is not a valid property on an instance of a DateTime.
Totally nonsense! This converts apples to potatoes.
TimeSpan and DateTime are there because a date is a completely different thing than a time span: What date should "one week and five hours" be???
Post a Comment