w1nk / node-odbc

unixODBC bindings for node
MIT License
90 stars 102 forks source link

How to prevent conversion of datetime string to JS Date object? #121

Closed netofri closed 6 years ago

netofri commented 6 years ago

When getting results from a query, datetime strings such as 2018-05-26 21:34:00.000 are automatically converted to JS Date objects.

Is there a way to get the results back as a raw string, they way it is saved in the DB, without any conversion?

Thanks

wankdanker commented 6 years ago

If the data type in the result set is a SQL_DATETIME or SQL_TIMESTAMP then it will go through the conversion to a Date object. There is no way around this other than hacking the source of the node-odbc project.

However, you might be able to change your query so that it is a string data type in the result set:

select convert(varchar(100), MyDateField) as date from MyTable

Not sure what database you are using, so that query may need to be different.

netofri commented 6 years ago

Using select convert(varchar(100), MyDateField) did the trick (Sybase IQ), though I was hoping there was a way to configure the module to not convert such fields.

Thanks