I suspect you really need a string representation, you really want:
string text = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fffffff", CultureInfo.InvariantCulture)
Note that:
- If you really don't want local time, use
UtcNow
instead of Now
. For timestamps, you almost always want UTC. - I doubt that you want to use the time separator of the current culture, so the
CultureInfo.InvariantCulture
specification - βMMβ means months, while βmmβ means minutes
- βHHβ means a 24-hour clock, while βhhβ means a 12-hour clock.
- "ff ..." is used for fractions of a second
For more information on custom date and time formatting, see MSDN .
However, I would strongly recommend that you try to avoid string conversions where possible. Why can't your stored procedure use only the appropriate DateTime
type instead of a string representation? You can then pass the value to the stored procedure as a DateTime
(via the command parameter), and you can get rid of randomly iterating over strings.
source share