Saturday, February 25, 2012

Only get dates

Can anyone help me create an expression for a column in a query that holds
only the date portion of a smalldatetime column? I've tried DatePart and had
a look around for other functions but I couldn't find anything. Thanks in
advance,
On Thu, 26 Aug 2004 22:19:04 -0700, Gary K wrote:

>Can anyone help me create an expression for a column in a query that holds
>only the date portion of a smalldatetime column? I've tried DatePart and had
>a look around for other functions but I couldn't find anything. Thanks in
>advance,
Hi Gary,
Use CONVERT to convert it to character, using a format without time (or
using a character column short enough that the time won't fit). If you
need it in datetime format without the time (you'll get the default time:
midnight), cast the result back to datetime format.
SELECT getdate()
SELECT CONVERT (varchar(8), GETDATE(), 112)
SELECT CAST(CONVERT (varchar(8), GETDATE(), 112) AS datetime)
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||Thanks Hugo, that takes care of the main problem I had. I still have to
convert it back into a date variable but thats easy now.
"Hugo Kornelis" wrote:

> On Thu, 26 Aug 2004 22:19:04 -0700, Gary K wrote:
>
> Hi Gary,
> Use CONVERT to convert it to character, using a format without time (or
> using a character column short enough that the time won't fit). If you
> need it in datetime format without the time (you'll get the default time:
> midnight), cast the result back to datetime format.
> SELECT getdate()
> SELECT CONVERT (varchar(8), GETDATE(), 112)
> SELECT CAST(CONVERT (varchar(8), GETDATE(), 112) AS datetime)
>
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)
>

No comments:

Post a Comment