cancel
Showing results for 
Search instead for 
Did you mean: 

DATEFORMAT / timestamp_format behavior discrepancy with documentation

Former Member
2,783

According to the documentation for DATEFORMAT / timestamp_format, MM represents month.

However, consider the output of:

SELECT DATEFORMAT('2017-12-30 12:34:56.789','YYYY:MM:DD:HH:NN:SS:SSS')

The expected value would be:

'2017:12:30:12:34:56:789'

However, the function returns:

'2017:34:30:12:34:56:789'

It appears that the database server (dbsrv12 version 17.0.4.2053, also tested on the last 12.0.1 EBF with same result) considers MM to be an alias for NN if preceded by a colon. That is not the documented behavior. I recent ran into an application that required all date parts to be separated by colons.

Of course, the workaround is YEAR(...)||':'||MONTH(...)||... but if the existing behavior is by design, should the documentation not reflect that? Or is this a bug? I presume that since the behavior seems to be specific to colons, that it is intentional.

VolkerBarth
Contributor

Can't tell on the intent/bug issue, but using a standard format and then replacing the delimiter might also do the trick...

SELECT REPLACE(DATEFORMAT('2017-12-30 12:34:56.789','YYYY.MM.DD:HH:NN:SS:SSS'), '.', ':')

returns '2017:12:30:12:34:56:780' (note the final zero) with v12.0.1.4403.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

This is documented behavior under the TIMESTAMP_FORMAT DCX article

"MM Two-digit month, or two-digit minutes if following a colon (as in HH:MM) "

Former Member
0 Kudos

Yep. I must be blind.

Answers (0)