简体   繁体   中英

Handling SQL date as string with node-mssql

I'm using node-mssql to get rows from a table that includes a date column (YYYY-MM-DD). I want to pass the date to a client application as a string in that same format. node-mssql is creating date objects, which I'm having to convert and slice at significant cost to get the format that I started with. sql.map.register(String, sql.Date) doesn't seem to work here (or I'm using it wrong). Is there a way to change how node-mssql handles the SQL date data type?

I'm having the same problem. sql.map.register is only for converting JS types to SQL types and I don't think there is any way to avoid SQL Date fields being converted into JS Date objects with node-mssql alone. I just changed my SQL query to convert to a formatted varchar instead of a Date type, eg: convert(varchar, birthday, 105) as dob .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM