SQL Server Cypress/tedious/mssql Conversion failed when converting date and/or time from character string

vlf7wbxs  于 2023-06-21  发布在  其他
关注(0)|答案(1)|浏览(152)

I get this error when I try to execute a simple SQL statement that properly works on the db.

The table:

hd_date     | hd_name
2025-04-21  | Ostermontag
2025-06-09  | Pfingstmontag

This works:

var sql = 'select hd_name from holidays '

cy.sqlServer(sql).then(function (result) {
  
  cy.log(result)

})

But as soon I include the hd_date I get the error. This

var sql = 'select hd_date, hd_name from holidays '

and this

var sql = 'select hd_name from holidays where year(hd_date) = 2025'

doesn't work.

Any ideas?

p8ekf7hl

p8ekf7hl1#

I found the solution. Tedious loggin to the SQL server with its own default language / time settings: us_english and mdy. You need to change it in the options. In my case with cypress in the file cypress.config.js

config.db = {
    "userName": "xxx",
    "password": "xxx,
    "server": "xxx",
    "options": {
      "database": "xxx",
      "encrypt": true,
      "rowCollectionOnRequestCompletion": true,
      "dateFormat": "dmy",
      "language": "Deutsch",
      "datefirst": 1
    }
  }

相关问题