Question

Using t-sql string functions

substring(convert(varchar, getdate(), 120),6, 11)

this will return mm-dd hh:mm

But then how do I get datetime format yy-mm-dd hh:mm ?

Thank you so much in advance.

Was it helpful?

Solution

Well, convert(varchar(25), getdate(), 120) returns:

          1
1234567890123456789
2013-08-08 01:43:49

So change:

substring(..., 6, 11)

To:

substring(..., 3, 14)

And you'll get:

13-08-08 01:43
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top