I couldn't pass in 2019-08-07T14:00:00-0400
to a stored procedure in SQL Server that takes a param in DATETIME
.
So how can I convert it to this format YYYY-MM-DD HH:MM:SS.SSS
in Java prior to calling the stored procedure?
I couldn't pass in 2019-08-07T14:00:00-0400
to a stored procedure in SQL Server that takes a param in DATETIME
.
So how can I convert it to this format YYYY-MM-DD HH:MM:SS.SSS
in Java prior to calling the stored procedure?
You can make use of SimpleDateFormat
class for reference visit here
SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ");
Date date = df.parse("2019-08-07T14:00:00-0400");
You will get java.util.Date
object in return which in turns you can use to store in database.
If you want to convert it in SQL queries you can use below query.
declare @abc nvarchar(19)='2019-08-07T14:00:00-0400'
select CONVERT(DATETIME,convert(varchar, @abc,121))