Corovei Andrei
Corovei Andrei

Reputation: 1668

VB and SQL datetime

How can I format a date in Visual Basic to be in sql 121 style (that is yyyy-mm-dd hh:mi:ss.mmm).

I realized that this format is not in the FormatDateTime list of objects.

I want to use this format for Reporting Services.

Upvotes: 1

Views: 14583

Answers (2)

HelaciousK
HelaciousK

Reputation: 13

Since this helped me, I thought I would add a bit. If passed into a method as a string then:

Shared SomeFunction(ByRef sStartDate as String)
Dim StartTime As DateTime = DateTime.Parse(sStartDate)
command.Connection = connection
command.CommandType = CommandType.StoredProcedure
command.CommandText = "SomeStoredProcedure"
command.Parameters.Add("@StartDateTime", SqlDbType.DateTime)
command.Parameters("@StartDateTime").Value = StartTime.ToString("yyyy-MM-dd HH:mm:ss.fff")

Cheers!

Upvotes: 0

Luke Girvin
Luke Girvin

Reputation: 13422

date.ToString("yyyy-MM-dd HH:mm:ss.fff")

Custom Date and Time Format Strings

Upvotes: 11

Related Questions