Abdi Abdi - 26 days ago 5
C# Question

How do I use the DateTime.Now.ToString(); in an sql command without having to remove the slashes

How do I use the

DateTime.Now.ToString();
in an sql command without having to remove the slashes. I am currently using substrings to remove the slashes, but its becoming abut nitty gritty because the dates can change from
12/12/2016
to
1/8/2016
.

Answer

Remove the slashes? If it's because you have to use another character instead, just use .Replace('/','-'); I would think that if you're using .NET, you won't have to convert to a string. Just pass the object as-is to the command in the SqlParameter.

var param = new SqlParameter("@dateParam", SqlDbType.DateTime);