Solved

Convert DateTime to Double

Posted on 2009-05-06
5
1,578 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 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