Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a date to format ddmmyy NOT ddmmyyyy

I am struggling to convert a date to format ddmmyy NOT ddmmyyyy.

The convert function allows all sorts of clever formatting but nothing close enough to fix using REPLACE.

Any help would be appreciated.

like image 806
RK43 Avatar asked Jan 11 '23 23:01

RK43


2 Answers

dd/mm/yy is British\French standard, so try this:

SELECT REPLACE(CONVERT(CHAR(8), [MyDateTime], 3), '/', '')
like image 74
Stefano Bafaro Avatar answered Jan 28 '23 12:01

Stefano Bafaro


SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 5),'-','') 

format number 5 will do dd-mm-yy and then you can remove the -'s

like image 27
Jwit Avatar answered Jan 28 '23 10:01

Jwit