How to convert DateTime to Double?

I want to convert the DateTime.Now to a double number...However, it seems

Convert.ToString(DateTime.Now) does not work...

Any method




Answer this question

How to convert DateTime to Double?

  • Anonomuys

    Hi

    I I think this snippet shoul do the trick:-


    private void ConvertDate_To_Double_Click(object sender, EventArgs e)
    {
    try

    {
    double date = Convert.ToSingle(DateTime.Now.ToOADate());
    MessageBox.Show("Date to Double is: " + date.ToString());
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.ToString());
    }
    }

    hope this helps



  • Khalnayak

    So that means I can calculate the value I get from DateTime.Now.ToOADate() and return the format of the time I like.

    Thanks!



  • Frank Carr

    The floating point not only contains the DAY from 30 December 1899, but the value on the right hand side of the decimal represents the seconds from 12 midnight...

    -Dave

  • Alexnaldo Santos

    If you wish to convert a DateTime to a double you can use the method ToOADate of the structure DateTime:

    DateTime.Now.ToOADate();



  • Thibaut Barrère

    What would you like this value to be based on Can it just be *any* double

    You could use DateTime.Now.Ticks (a long): The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001.

    The DateTime.Now.ToOADate() would return an OLE Automation date. An OLE Automation date is implemented as a floating-point number whose value is the number of days from midnight, 30 December 1899.

    -Ernst


  • How to convert DateTime to Double?