Link to home
Start Free TrialLog in
Avatar of bmanmike39
bmanmike39

asked on

How do you convert a date object to double?

How do you convert a date object to double?


DateTime com = DateTime.Now;

DateTime date1 = DateTime.MinValue;
DateTime date2 = DateTime.MinValue;

DateTime.TryParse(Label1.Text, out date1);
DateTime.TryParse(com.ToShortTimeString(), out date2);

TimeSpan ts = new TimeSpan();
ts = (date1 - date2);

double tss = Convert.ToDouble(ts);

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

What does the double represent? You might find the Ticks member suits your needs.
Sorry, that link was for the DateTime class, but the TimeSpan class also has a Ticks member. There are also the TotalMilliseconds, TotalSeconds, TotalMinutes, and TotalHours properties which may be useful.
ASKER CERTIFIED SOLUTION
Avatar of Rick
Rick

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you use this program then this will throw exception of invalid cast....because you can not convert cast timespan to double.

what you excetly want from timespan that will get from the object of timespan ts


Regards,
nishant
Avatar of bmanmike39
bmanmike39

ASKER

Thanks!!
LOL. Calling ToDouble on a property that returns Double?? Perhaps if someone had provided links to the documentation we would have known that TotalMilliseconds returned a Double...   Oooops! Someone did  : \