From: Meatbird í on
Hi:
I got a performance issue when I try to load data from a database. The column in my db looks like below:
"datetime" ,"num1","num2"............"num30" and there is millions of records.
When I fetch the data with database tool boxes ,the result of "datetime" column
is stored in string format which consumed huge memory space and took great cpu time
to convert them into datenum before I can use them.

Is there any approach that I can convert the date time format data into numeric data while loading from a database?

Best regards!

guoshouyi


From: Oleg Komarov on
"Meatbird í" <guoshouyi0219(a)gmail.com> wrote in message <hunhma$f6r$1(a)fred.mathworks.com>...
> Hi:
> I got a performance issue when I try to load data from a database. The column in my db looks like below:
> "datetime" ,"num1","num2"............"num30" and there is millions of records.
> When I fetch the data with database tool boxes ,the result of "datetime" column
> is stored in string format which consumed huge memory space and took great cpu time
> to convert them into datenum before I can use them.
>
> Is there any approach that I can convert the date time format data into numeric data while loading from a database?
>
> Best regards!
>
> guoshouyi

I suggest you to convert into serial dates before downloading.

-- T-SQL
DECLARE @oneDate DATETIME = '01/01/2010'
SELECT CONVERT(BIGINT, @oneDate,103) -- 40177

% MATLAB
datenum('01/01/2010','dd/mm/yyyy')
ans =
734139

So, the difference is 734139 -40177 = 693962

Before downloading convert into bigint the dates (day precision) and add 693962 to rescale to MATLAB initial 0.
SELECT CONVERT(BIGINT, @oneDate,103) + 693962 --734139

Oleg