Sunday, February 12, 2012

About Function:GETDATE()

Hello,
I useSELECT CONVERT(VARCHAR(30),GETDATE(),105)
and get the now data
25-04-2006,
but if i want to get the data format is 2006-04-25
How?
Thank you!Hi

There is a more efficient way of stripping the time portion off however it doesn't quite match your format. Second function is perhaps more what you are after.
SElECT DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)

SELECT CONVERT(CHAR(10),GETDATE(),120)

HTH|||the result is right! but

SELECT CONVERT(CHAR(10),GETDATE(),120)
is it insecurely?|||Um... I don't know. What do you mean by "insecurely"?

BTW - you can look up the constants in the BOL entry for CAST and CONVERT too.|||ok,thank you!

No comments:

Post a Comment