Convert DateTime to Double


Hi experts!

  Im using C# 2008 , WinForm NET 2. I need somethink not very common, but I used to work with date like double and this save me many trouble with date format.

I have DateTime variable and want to get it Double value (to be more clear, I need only date part without time so will truncate only integer part). How to do this ?  I need some think like :

       DateTime dt = DateTime.Now;
           
       double dtDOuble = Convert.ToDouble(dt);

 This produce error &


dvplayltdAsked:
Who is Participating?
 
cauosCommented:
double dtDOuble = double.Parse(dt.ToShortDateString().Replace("/",""));

the char "/" depand on the system time format maybe in you machine like "-"
0
 
dvplayltdAuthor Commented:
To caous

 Thank for offer, but give error. Can you check for some mistake  in VS2008 ?
0
 
cauosCommented:
what is the error appears
0
 
dvplayltdAuthor Commented:
Very good, thank you! P.S: I use this in SQL Server 2005, it is
double date = Convert.ToSingle(DateTime.Now.ToOADate()) - 2;

and work very well.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.