Skip to main content
Open

Add a SQL Server Date format to @DateFormatter function and DateCalculator trans

Related products:Transformers
mark2atsafe
  • mark2atsafe
    mark2atsafe

cfvonner
Supporter

***Note from Migration:***

Original Title was: Add a SQL Server Date format to @DateFormatter function and DateCalculator transformer


Microsoft SQL Server (at least on 2012) only allows timestamps containing milliseconds (3 decimal places for fractional seconds) to be written to datetime and datetime2 columns. Dates generated by the @DateTimeNow() function automatically include nanoseconds (9 decimal places for fractional seconds). There is currently no way in the @DateTimeFormat function or DateCalculator transformer to only return milliseconds. Using either the "ISO" format shortcut, or using the %S flag always passes nanoseconds. One workaround I found was to wrap the @DateTimeNow() in a @Format() function like this: @DateTimeFormat(@Format(%.3f,@DateTimeNow()),ISO) to truncate the extra digits.

I propose adding a "SQLServer" shortcut that returns the timestamp with only millisecond precision, and a flag of some sort that returns the seconds to millisecond precision.

2 replies

cfvonner
Supporter
Forum|alt.badge.img+19
  • Author
  • Supporter
  • March 27, 2018

I should clarify that this isn't a problem using Writers or FeatureWriter transformers. I encountered the issue in a SQLExecutor transformer because I needed to do an update on only certain records.


sdepriest
Contributor
Forum|alt.badge.img+9
  • Contributor
  • January 13, 2021

I propose to have some ability to indicate the precision of seconds you need. In my case I need only 6 digits for fractional seconds, which is called microseconds I believe. So far I've just used a SubString() to chop off that last digit, but it would be cleaner if there was a flag or option I could add to the DateTimeNow() function to indicate how precise I'd like the fractional seconds to be.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings