Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert DateTime to Double

Posted on 2009-05-06
5
Medium Priority
?
1,600 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

885 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