Solved

Convert DateTime to Double

Posted on 2009-05-06
5
1,571 Views
Last Modified: 2013-12-17

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 &


0
Comment
Question by:dvplayltd
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:cauos
Comment Utility
double dtDOuble = double.Parse(dt.ToShortDateString().Replace("/",""));

the char "/" depand on the system time format maybe in you machine like "-"
0
 

Author Comment

by:dvplayltd
Comment Utility
To caous

 Thank for offer, but give error. Can you check for some mistake  in VS2008 ?
0
 
LVL 4

Expert Comment

by:cauos
Comment Utility
what is the error appears
0
 
LVL 13

Accepted Solution

by:
copyPasteGhost earned 500 total points
Comment Utility
0
 

Author Closing Comment

by:dvplayltd
Comment Utility
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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now