We help IT Professionals succeed at work.

How do you convert a date object to double?

bmanmike39
bmanmike39 asked
on
Medium Priority
438 Views
Last Modified: 2013-12-16
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

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
What does the double represent? You might find the Ticks member suits your needs.
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
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.
Commented:
You'll need to specify if you want that value in minutes, seconds, milliseconds, etc.

      double tss = Convert.ToDouble(ts.TotalMilliseconds);
nishant joshiTechnology Development Consultant
CERTIFIED EXPERT

Commented:
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

Author

Commented:
Thanks!!
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
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  : \

Explore More ContentExplore courses, solutions, and other research materials related to this topic.