I am bringing in some data from Analysis Services (SSAS), and I am having trouble converting the dates into the right datetime format. From the query we get the cell array of dates to be:
We want to get this into datetime format, so we use a bespoke function to make this work:
function OutputArray = DateConversion(DateArray)
Times = datetime(DateArray,'format','dd/MM/yyyy HH:mm:00');
Times(isnat(Times),1) = datetime(DateArray(isnat(Times),1),...
OutputArray = Times;
Where in this case the DateArray that will be entered in will be FCStruct.StartDateTime, and this is also the output. This is run as follows:
FCStruct.StartDateTime = DateConversion(FCStruct.StartDateTime);
This works, however, we get warnings:
Warning: Successfully read the date/time text using the format 'MM/dd/uuuu HH:mm:ss', but their format is ambiguous and could also be 'dd/MM/uuuu HH:mm:ss'. Specify a format
character vector to avoid ambiguity.
> In guessFormat (line 66)
In datetime (line 610)
In DateConversion (line 17)
In CustDemandComparison (line 83)
What is the issue with the datestring/datetime conversion code? I did have a loop that done this, however, it was ~35 times slower than this method. It seems that I am using the format as expected however, there may be a more efficient way of doing this by using cellfunctions.