Concatenate date for JSON payload

  • Afternoon,

    I'm working on encoding a json token and I'm getting this - "Conversion failed when converting date and/or time from character string"

    Ex:

    --2016 compatibility

    declare @data varbinary(max)

    declare @base64string varchar(max)

    select @data = convert(varbinary(max), '{"note":"ALL THESE WORLDS ARE YOURS...","iat":' + getdate() + ', "valid":"true"}');

    select @base64string = cast('' as xml).value('xs:base64Binary(sql:variable(''@data''))', 'varchar(max)')

    Any help,

    Thanks!

    • This topic was modified 5 years ago by  delizat4g. Reason: Not enough information

    Code-Blooded

  • You need to explicitly convert getdate(), for example:

    CONVERT(CHAR(8), GETDATE(), 112)

    --Vadim R.

  • That worked perfect. Thanks for the reply!

    Code-Blooded

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply