how to insert date and time in database table using matlab database toolbox

is it possible to insert the current time in table using the code datestr(now);? I am getting this error
Error using database/fastinsert (line 86) Input data must be a cell array, matrix, or structure
Error in licenseplate>pushbutton23_Callback (line 615) fastinsert(conn,tableName,colnames2,txt);
in the command window.
here's the code:
conn = database('vlmsystem','admin','admin');
dbpath = 'C:\Users\Sony Vaio\Documents\Task\0.1 Systems\System 1 - edited\Appendix\vlogdbase.mdb';
tableName = 'vehicleLog';
colnames = {'plate_number','date_time','login_logout'};
colnames1 = {'plate_number'};
colnames2 = {'date_time'};
colnames3 = {'login_logout'};
txt = datestr(now);
fastinsert(conn,tableName,colnames2,txt);
close(conn);

 採用された回答

the cyclist
the cyclist 2013 年 10 月 24 日
Does it work if you put your result in a cell array?
txt = {datestr(now)};

3 件のコメント

Lloyd
Lloyd 2013 年 10 月 24 日
Yes, missed putting it but still, I'm getting this error:
txt =
'25-Oct-2013 02:06:52'
Error using database/datainsert (line 129)
Unable to insert element in row 1 column 1, 25-Oct-2013 02:06:52.
Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
Error in licenseplate>pushbutton23_Callback (line 615)
datainsert(conn,tableName,colnames2,txt);
and it's not registering in the database.
Lloyd
Lloyd 2013 年 10 月 24 日
is there a way to change the format of the date and time? I think the current format is dd-mm-yyy hh:mm:ss
the cyclist
the cyclist 2013 年 10 月 25 日
Yes. datestr() accepts a second input argument for the format. Try
datestr(now,'yyyy-mm-dd HH:MM:SS')

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2013 年 10 月 24 日

コメント済み:

2013 年 10 月 25 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by