Monday, February 20, 2012

Problem with date

Is there a shorter (an easier) way to obtain a date in this format
'14/10/2004', instead of writing the following query?

select rtrim(ltrim(cast(DATEPART(m, GETDATE()) as char)))+ '/'+
rtrim(ltrim(cast(DATEPART(d, GETDATE()) as char))) + '/' +
rtrim(ltrim(cast(DATEPART(yy, GETDATE()) as char)))
as dato from dummy

Thank you!
Federica"Federica T" <fedina_chicca@.N_O_Spam_libero.it> wrote in message
news:ckltfm$bab$1@.atlantis.cu.mi.it...
> Is there a shorter (an easier) way to obtain a date in this format
> '14/10/2004', instead of writing the following query?
> select rtrim(ltrim(cast(DATEPART(m, GETDATE()) as char)))+ '/'+
> rtrim(ltrim(cast(DATEPART(d, GETDATE()) as char))) + '/' +
> rtrim(ltrim(cast(DATEPART(yy, GETDATE()) as char)))
> as dato from dummy
> Thank you!
> Federica

See CONVERT() in Books Online:

select convert(char(10), getdate(), 103)

Or you can format dates in the client application - it can be easier to
provide the correct regional formatting for different clients that way. You
might not need to be able to do that in your situation, of course.

Simon|||> See CONVERT() in Books Online:
> select convert(char(10), getdate(), 103)
> Or you can format dates in the client application - it can be easier to
> provide the correct regional formatting for different clients that way.
You
> might not need to be able to do that in your situation, of course.
> Simon
Thank you, Simon!

No comments:

Post a Comment