0

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);

EDIT using txt = {datestr(now)} :

I'm getting this error and it's not recording the date in the table.

licenseplate

txt =

'25-Oct-2013 02:03:59'
Error using database/datainsert (line 129)
Unable to insert element in row 1 column 1, 25-Oct-2013 02:03:59.
Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]

Error in licenseplate>pushbutton23_Callback (line 615)
datainsert(conn,tableName,colnames2,txt);
3
  • Have you tried following the suggestion in the error-message, putting the datestring into a cell-array?: txt = {datestr(now)} Commented Oct 24, 2013 at 17:49
  • Tried doing the suggestion but still, it's not exporting the data into the table. Commented Oct 24, 2013 at 18:11
  • @sebastian 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 Commented Oct 24, 2013 at 18:49

1 Answer 1

1

Format the datestr according to your database. How to format datestrings is described in the datestr docs. You can almost copy&paste that from the last error message:

txt = {datestr(now, 'yyyy-mm-dd HH:MM:SS')}

should be fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.