Question:Table 1 has a date column in the following format:
Table 2 has a date columns in this format:
2021-05-01 03:00.0000000(edited from 2021-05-01 03:00:00)
How can I show the date in Table 2 to be like the date in Table 1?
I search here and elsewhere and I found links like the following: https://www.mssqltips.com/sqlservertip/2655/format-sql-server-dates-with-format-function/ Sql Server select datetime without seconds
but I’m still having difficulty with my code:
SELECT FORMAT(MAX(date1), 'yyyy-mm-dd HH:mm') FROM table2.
What am I doing wrong?
Answer:Looking at the
formatdocs for dates and times and the date and time data types, we see
mmis minutes and
convert, but that also means using obscure convert codes.
smalldatetimeand table2 is a
datetime2. If you have to do this conversion a lot, consider making your datetime columns all the same type.
If you have better answer, please add a comment about this, thank you!