Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, July 17, 2015 3:23 PM
Hi all,
I have a time-series Data, stored in my DataBase in the Format
Date Price
03-Jan-86 15.6
10-Jan-86 63.2
17-Jan-86 56.9
24-Jan-86
31-Jan-86
07-Feb-86
and i want to to store them in a List<DateTime> and then Convert this list to List<double> in order to place them in a numeric variable for some R.NET statistical calculations
I have load them in the List<DateTime> (the first column) but now how can i convert em to double list?
All replies (6)
Sunday, July 19, 2015 11:49 AM âś…Answered | 1 vote
Hi thanks for your response. I dont have clear answer but guessing because i never done it before.
I have checked how R studio imports the Data and from this format 03-Jan-86 it imports data into a DataFrame
at this format Jan 03, 1986.
I am close to find the solution but i have been stacked at this point for a days
Hello,
DateTime.ToOADate() method will return a double Ole Automation date. I think this is what you want.
If you want to convert the datetime to a custom format like "Jan 03, 1986", you can use the format string like this:
DateTime date=Convert.ToDateTime("03-Jan-86");
string customDate = date.ToString("MMM dd, yyyy");
If it's not correct, I think you need to post your question in the R.NET codeplex site, as the owner of this opensource library for how to get the right date format:
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Friday, July 17, 2015 3:33 PM
List<DateTime> dates; //assuming you loaded the values to this list
List<long> longDates = new List<long>();
foreach(var d in dates)
{
longDate.Add(d.Ticks);
}
or
List<long> longDate = new List<long>();
longDate.AddRange(dates.Select(d => d.Ticks));
sivanitha
Friday, July 17, 2015 3:50 PM
Hi Sivathina before i mark it as answered i would like to make a clarification
Why did you save it in a long and not in a double?
and the second one if i try to check the type it returns me MessageBox.Show(longDates.GetType().ToString());
Generic List [System.int64]. Can i use it as numeric as well?
Thanks a lot
I think i almost done
Aris
Friday, July 17, 2015 3:58 PM
DateTime.Ticks returns a long value - the number of 100-nanosecond intervals since midnight January 1st, 0001.
How exactly do you expect a date and time to be represented as a numeric value?
Friday, July 17, 2015 4:23 PM
Hi thanks for your response. I dont have clear answer but guessing because i never done it before.
I have checked how R studio imports the Data and from this format 03-Jan-86 it imports data into a DataFrame
at this format Jan 03, 1986.
I am close to find the solution but i have been stacked at this point for a days
Sunday, July 19, 2015 11:21 PM
YES! this is the correct answer! So i will give a better description in case some in the future has the same problem.
I am loading all my Date Column from MySql in this list
List<DateTime> listA = new List<DateTime>(); and i convert this list to double in order to use it as numeric vecror in R.NET
List<double> listAtoDouble = new List<double>();
foreach (var d in listA)
{
listAtoDouble.Add(d.ToOADate());
}
**** NOTE
The only problem now is that they dont appear in an appropriate format. Dates apperar like 32000 34000 36000