Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert DateTime to Double

I've created a DateTime value from an item being clicked in a listBox. It's in the format dd/MM/yyyy hh:mm:ss. I'm want to zoom in on a ten minute period with the clicked event in the middle. My current code is as follows (where zoom_time is the DateTime to zoom to on my chart;

chart1.ChartAreas[0].AxisX.Minimum = (Convert.ToDouble(zoom_time.AddMinutes(-5)));
chart1.ChartAreas[0].AxisX.Maximum = (Convert.ToDouble(zoom_time.AddMinutes(5)));

This breaks saying

"invalid cast from DateTime to double"

Any ideas guys?

like image 907
tommy_20 Avatar asked Jul 23 '13 08:07

tommy_20


People also ask

How to convert DateTime to double matlab?

You can use datenum to convert each your data to double.

What is FromOADate?

FromOADate() method in C# is used to return a DateTime equivalent to the specified OLE Automation Date.

How do I change the date format in razor view?

You can use the DisplayFormat data annotation attribute on the model property to specify the format and ensure that the format also applies when the value is in "edit mode" (a form control): [BindProperty, DisplayFormat(DataFormatString = "{0:yyyy-MM-ddTHH:mm}", ApplyFormatInEditMode = true)]


3 Answers

You can use DateTime.ToOADate(), if you mean ole automation date by double

like image 132
BudBrot Avatar answered Oct 07 '22 22:10

BudBrot


Thanks for that!

For reference, the following works best;

            double start = (zoom_time.AddMinutes(-1)).ToOADate();
            double end = (zoom_time.AddMinutes(1)).ToOADate();

            chart1.ChartAreas[0].AxisX.Minimum = start;
            chart1.ChartAreas[0].AxisX.Maximum = end;
like image 31
tommy_20 Avatar answered Oct 07 '22 23:10

tommy_20


You have to use the ToOADate() methode like the following:

chart1.ChartAreas[0].AxisX.Minimum = zoom_time.AddMinutes(-5).ToOADate();
chart1.ChartAreas[0].AxisX.Maximum = zoom_time.AddMinutes(5).ToOADate();

Edit:

Should have refreshed my page before answering. :)

like image 33
Rand Random Avatar answered Oct 08 '22 00:10

Rand Random