在golang中将datetimeoffset转换为datetime?

时间:2019-02-24 01:24:39

标签: sql-server go postman go-gorm

我无法将datetimeoffset转换为datetime。我试图使用postman方法将body插入到数据库中。但是结果是EXEC SMSBlast2Procedure '9', '087871723282', 'adsbjkadhdhad', '0001-01-01 00:00:00', '0001-01-01 00:00:00' , 'asjdasjgdjasgdjsad', '2019-02-24 08:17:54',在邮递员中,我的输入如下图所示:

enter image description here

响应json如下图所示:

enter image description here

但是当我检查控制台结果WillBeSentDate是0001-01-01 00:00:00和0001-01-01 00:00:00时,为什么?

将我的代码从datetimeoffset设置为datetime。

    json.NewDecoder(r.Body).Decode(&smsblats)

    var count int64 = 0
    db.Debug().Table("SMSBlast2").Count(&count)
    count++
    fmt.Println(count)

   formatWill, _ := time.Parse(time.RFC3339, smsblats.WillBeSentDate.String())
   formatSent, _ := time.Parse(time.RFC3339, smsblats.SentDate.String())


    db.Debug().Raw("EXEC SMSBlast2Procedure ?, ?, ?, ?, ? , ?, ?",
        count,
        smsblats.MobilePhone,
        smsblats.Output,
        formatWill,
        formatSent,
        smsblats.Status,
        time.Now()).Scan(smsblats)
    w.Header().Set("Content-Type", "application/json")
    w.Header().Set("Response-Code", "00")
    w.Header().Set("Response-Desc", "Success")
    json.NewEncoder(w).Encode(smsblats)

我的代码有什么问题?该错误显示mssql:将数据类型datetimeoffset转换为datetime时出错,我正在使用sql server作为数据库,存储过程如下所示

USE [CONFINS]
GO
/****** Object:  StoredProcedure [dbo].[SMSBlast2Procedure]    Script Date: 2/20/2019 5:06:21 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SMSBlast2Procedure]
(
@sequenceid int,
@mobilephone varchar(20),
@output varchar(20),
@willbesentdate datetime,
@sentdate datetime, 
@status varchar(60),
@dtmupd datetime
)
AS
INSERT INTO SMSBlast2(SequenceID,MobilePhone,Output, WillBeSentDate, SentDate, Status, DtmUpd) VALUES (@sequenceid , @mobilephone, @output, @willbesentdate, @sentdate, @status, @dtmupd)

0 个答案:

没有答案