I'm replacing my C# code for performance reasons with a sql query:
CreatedAt.ToString("ddMMyy", System.Globalization.CultureInfo.InvariantCulture)
returns the creation-date as 140115
(for today). Simple enough in C#, but how do i get this in T-SQL?
I have tried:
REPLACE(CONVERT(CHAR(10), ChargeArrival.CreatedAt, 103), '/', '')
which is almost correctly, but the year has four digits instead of two, so 14012015
instead of 140115
.
The default string literal format, which is used for down-level clients, complies with the SQL standard form that is defined as YYYY-MM-DD. This format is the same as the ISO 8601 definition for DATE.
As the docs for CONVERT
state, use 103
if you want the century and 3
if you dont:
REPLACE(CONVERT(CHAR(10), ChargeArrival.CreatedAt, 3), '/', '')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With