Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datetime.now as TimeSpan value?

Tags:

I need the current Datetime minus myDate1 in seconds.

DateTime myDate1 = new DateTime(1970, 1, 9, 0, 0, 00); DateTime myDate2 = DateTime.Now;  TimeSpan myDateResult = new TimeSpan();  myDateResult = myDate2 - myDate1; 

.
.
I tried different ways to calculate but to no effect.

TimeSpan mySpan = new TimeSpan(myDate2.Day, myDate2.Hour, myDate2.Minute, myDate2.Second); 

.
The way it's calculated doesn't matter, the output should just be the difference these to values in seconds.

like image 859
MrMAG Avatar asked Aug 13 '12 07:08

MrMAG


People also ask

How do I convert DateTime to TimeSpan in Python?

To convert a DateTime to a TimeSpan you should choose a base date/time - e.g. midnight of January 1st, 2000, and subtract it from your DateTime value (and add it when you want to convert back to DateTime ). If you simply want to convert a DateTime to a number you can use the Ticks property.

What is TimeSpan value?

A TimeSpan value represents a time interval and can be expressed as a particular number of days, hours, minutes, seconds, and milliseconds.


1 Answers

Code:

TimeSpan myDateResult = DateTime.Now.TimeOfDay; 
like image 164
YC Chiranjeevi Avatar answered Sep 21 '22 17:09

YC Chiranjeevi