Solved

Convert DateTime to Double

Posted on 2009-05-06
5
1,575 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
ID: 24312998
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
ID: 24313200
To caous

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

Expert Comment

by:cauos
ID: 24313537
what is the error appears
0
 
LVL 13

Accepted Solution

by:
copyPasteGhost earned 500 total points
ID: 24314520
0
 

Author Closing Comment

by:dvplayltd
ID: 31578386
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

17 Experts available now in Live!

Get 1:1 Help Now