I have problem with converting a datetimeoffset
to datetime
. I have tried to insert into my database using postman with method post in body. But the result is EXEC SMSBlast2Procedure '9', '087871723282', 'adsbjkadhdhad', '0001-01-01 00:00:00', '0001-01-01 00:00:00' , 'asjdasjgdjasgdjsad', '2019-02-24 08:17:54'
, where in postman I am inputting like picture below :
respon json like picture below :
but when I check in console result WillBeSentDate is 0001-01-01 00:00:00 and 0001-01-01 00:00:00, why ?
Here my code to datetimeoffset to 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)
What wrong with my code? The error says
Error converting data type datetimeoffset to datetime
I'm using SQL Server for database, a stored procedure like this:
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)