Skip to content

DATETIME converted to string but Tedious driver expects date #546

Closed

Description

@asage-me

I initially made a pull request on the tedious project to match DATETIME2 with DATETIME in that it converts the parameter (a string) to a date but a contributor over there said the whole file needs re-though. In the meantime we are stuck with a broken node as passing a DATETIME parameter causes the process to crash. Starting on line 166 https://github.com/patriksimek/node-mssql/blob/master/lib/datatypes.js you take a date and convert it to a string which results in the process crashing with "TypeError: parameter.value.getTime is not a function" The only two solutions is to convert the string to a date (currently I have modified the tedious driver to to this) or send a date to the tedious driver. I hope you two can work it out.

Activity

  1. changed the title [-]DATETIME converted to number but Tedious driver expects date[/-] [+]DATETIME converted to string but Tedious driver expects date[/+] on Oct 23, 2017
  2. mjodeh commented on Jul 29, 2018

    @mjodeh

    node_module\tedious\lib\data-types\datetime.js
    from line 29:

    if (options.useUTC) {
    var dateTest = new Date(parameter.value);
    days = Math.floor((parameter.value - UTC_EPOCH_DATE.getTime()) / (1000 * 60 * 60 * 24));
    seconds = dateTest.getUTCHours() * 60 * 60;
    seconds += dateTest.getUTCMinutes() * 60;
    seconds += dateTest.getUTCSeconds();
    milliseconds = seconds * 1000 + dateTest.getUTCMilliseconds();
    } else {
    var dateTest = new Date(parameter.value);
    dstDiff = -(dateTest.getTimezoneOffset() - EPOCH_DATE.getTimezoneOffset()) * 60 * 1000;
    days = Math.floor((dateTest.getTime() - EPOCH_DATE.getTime() + dstDiff) / (1000 * 60 * 60 * 24));
    seconds = dateTest.getHours() * 60 * 60;
    seconds += dateTest.getMinutes() * 60;
    seconds += dateTest.getSeconds();
    milliseconds = seconds * 1000 + dateTest.getMilliseconds();
    }

  3. dhensby commented on Mar 8, 2019

    @dhensby
    Collaborator

    I'm not really following this, @willmorgan: thoughts?

  4. willmorgan commented on Mar 8, 2019

    @willmorgan
    Collaborator

    It's a Tedious issue I'm afraid.

  5. swordsreversed commented on Jul 30, 2019

    @swordsreversed

    @atsage do you know if this ever got fixed? Using this library for the first time and having the same problem. If not do you mind sharing your modifications?

  6. mjodeh commented on Jul 30, 2019

    @mjodeh

    @swordsreversed Just convert the parameter you are passing to "Date" type and do not pass it as a string object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions