hi friends,
I want to convert datetime to date.
example
select dt from abc where dt between @.dt1 and @.dt2
dt holds the value '2004-08-02 12:12:28.000'
i want dt to eliminame time before checking.
thanks
vanithaVanitha
You can use
select dt from abc where dt >=@.dt1 and dt< dateadd(day,1,@.dt2) ( It gives an
ability to use an index on dt column)
Lookup CONVERT function in the BOL
"Vanitha" <Vanitha@.discussions.microsoft.com> wrote in message
news:A2648D8E-CCD2-45DF-91AB-5DC852203A2C@.microsoft.com...
> hi friends,
> I want to convert datetime to date.
> example
> select dt from abc where dt between @.dt1 and @.dt2
> dt holds the value '2004-08-02 12:12:28.000'
> i want dt to eliminame time before checking.
> thanks
> vanitha
>|||SELECT CONVERT(DATETIME,(CONVERT(VARCHAR(12), Getdate(),7)))
"Vanitha" wrote:
> hi friends,
> I want to convert datetime to date.
> example
> select dt from abc where dt between @.dt1 and @.dt2
> dt holds the value '2004-08-02 12:12:28.000'
> i want dt to eliminame time before checking.
> thanks
> vanitha
>|||> SELECT CONVERT(DATETIME,(CONVERT(VARCHAR(12), Getdate(),7)))
This will fail if you have certain regional settings, e.g. SET LANGUAGE
RUSSIAN
Much safer to use ISO standard date formats, like YYYYMMDD; in this specific
case, better to use a real datetime instead of relying on string formatting,
then you can use an index (which is ideal for this type of query).
DECLARE @.dt SMALLDATETIME
SET @.dt = DATEADD(DAY, 0, DATEDIFF(DAY, 0, GETDATE()))
SELECT ...
WHERE dt >= @.dt AND dt < @.dt+1
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment