-2

I am executing this query in SQL Server 2008

 SELECT (CONVERT(DATE, GETDATE()))

and it shows the result 2013-07-22.

I need to print this result as 22713, where 22 is the date 7 is the month 13 is the year.

How could I do this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
sidhewsar
  • 136
  • 2
  • 8
  • 17

3 Answers3

1
SELECT CAST(DATEPART(dd,GETDATE()) as varchar(10))
  +CAST(DATEPART(mm,GETDATE()) as varchar(10))
  +RIGHT(CAST(DATEPART(YY,GETDATE()) as varchar(10)),2)

SQLFiddle demo

valex
  • 23,966
  • 7
  • 43
  • 60
1

1) It bad practice use SQL for string operation. More right external tools 2) I use other RDBMS. Below query work with it:

select (extract(day from ua.stamp))||(extract(month from
ua.stamp))||(extract(year from ua.stamp)) from useractions ua

Furthemote, this link can help you: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/55d23bb0-6e1e-4a03-9bed-94e7c755ec4d/get-the-day-from-date-value-in-sql-server

Michael Kazarian
  • 4,376
  • 1
  • 21
  • 25
0

You could read the string, go over it with a tokenizer, split it and put it back together the way you want it to be. What language are you using?

AnyOneElse
  • 406
  • 2
  • 6
  • 17