4

In PostgreSQL, there is a command, \dC+ I can use in psql \dC+,

\dC[+]  [PATTERN]      list casts

To lists the possible CASTS. This is useful, because I can easily find out what I can use to cast to timestamp,

\dC+ timestamp
                                             List of casts
         Source type         |         Target type         |  Function   |   Implicit?   | Description 
-----------------------------+-----------------------------+-------------+---------------+-------------
 abstime                     | timestamp without time zone | timestamp   | yes           | 
 date                        | timestamp without time zone | timestamp   | yes           | 
 timestamp without time zone | abstime                     | abstime     | in assignment | 
 timestamp without time zone | date                        | date        | in assignment | 
 timestamp without time zone | timestamp without time zone | timestamp   | yes           | 
 timestamp without time zone | timestamp with time zone    | timestamptz | yes           | 
 timestamp without time zone | time without time zone      | time        | in assignment | 
 timestamp with time zone    | timestamp without time zone | timestamp   | in assignment | 

Is there any command like that in SQL Server? How can I find what I can CAST to DateTime2? Is this documented anywhere?

6

The Microsoft Docs page for CAST and CONVERT provides a great matrix of conversions in SQL Server.

The image included in the above page:

enter image description here

As far as I know, there is no built-in mechanism for displaying a list of valid casts.

  • 4
    Worth noting: there is an implicit cast from timestamp to money. Our god is an awesome god. – Evan Carroll Jul 13 '18 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.