3

Say I'm given a column "Date" with values that look like: 03/10/86, 06/10/86, 07/10/86, etc...

It is not as simple as doing Frame.indexRowsDate("Date"). My current solution is to create on the Excel 3 extra columns:

  • Year
  • Month
  • Day

with values:

  • =Year(A2)
  • =Month(A2)
  • =Day(A2)

(for row 2, where A is the column with the dates)

and then use this function:

let toDateTime (os:ObjectSeries<_>) =
  let year = (os.Get "Year") :?> int)
  let month = (os.Get "Month" :?> int)
  let day = (os.Get "Day" :?> int)
  DateTime(year,month,day)

Frame.indexRowsUsing toDateTime frame

Solution Given the provided answer, the new toDateTime looks like this:

let toDateTime (os:ObjectSeries<_>) =
  DateTime.Parse((os.Get "Date") :?> string)
Lay González
  • 2,901
  • 21
  • 41

1 Answers1

3

You cant use the constructor function for DateTime and feed it a string.

let d = new DateTime("03/10/86")

but you can use the static member TryParse which will return a tuple to you

let (success, date) = DateTime.TryParse("03/10/86")
if success then
   //use date here
else
   //do some error handling
robkuz
  • 9,488
  • 5
  • 29
  • 50