Sunday, February 12, 2012

Convert Date-Time Field to Date

Using Query Analyzer and a select statement, how do you
convert a date-time field to a date field?
Thanks
There is no date-only datatype in SQL Server. Both DATETIME and
SMALLDATETIME have time components. What I think you want to do is format
your DATETIME data as a string?
You can use CONVERT and apply a style. Look up all of the styles in BOL.
Here's an example, using style 107:
SELECT CONVERT(CHAR(12), GETDATE(), 107) AS FormattedDate
"Charles Allen" <callen@.bkd.com> wrote in message
news:2cc7c01c46916$63b21a30$a301280a@.phx.gbl...
> Using Query Analyzer and a select statement, how do you
> convert a date-time field to a date field?
> Thanks
|||Thank you for the incredibly quick reply.

>--Original Message--
>There is no date-only datatype in SQL Server. Both
DATETIME and
>SMALLDATETIME have time components. What I think you
want to do is format
>your DATETIME data as a string?
>You can use CONVERT and apply a style. Look up all of
the styles in BOL.
>Here's an example, using style 107:
>
>SELECT CONVERT(CHAR(12), GETDATE(), 107) AS FormattedDate
>
>"Charles Allen" <callen@.bkd.com> wrote in message
>news:2cc7c01c46916$63b21a30$a301280a@.phx.gbl...
>
>.
>

No comments:

Post a Comment