Is there an easy way to convert a datetime field to a date in a query? I
work with an ERP system that stores dates in datetime fields. All I need is
the date portion.
ThanksSee function "convert" in BOL.
Example:
select convert(char(10), getdate(), 101)
go
AMB
"Charles Allen" wrote:
> Is there an easy way to convert a datetime field to a date in a query? I
> work with an ERP system that stores dates in datetime fields. All I need i
s
> the date portion.
> Thanks
>
>|||You can use a combination of the DATEPART and CONVERT functions to get a
varchar:
select convert(varchar(2), datepart(mm,getdate()))+'/'+convert(varchar(2),
datepart(dd,getdate()))+'/'+convert(varchar(4), datepart(yyyy, getdate())) a
s
DateOnly
"Charles Allen" wrote:
> Is there an easy way to convert a datetime field to a date in a query? I
> work with an ERP system that stores dates in datetime fields. All I need i
s
> the date portion.
> Thanks
>
>|||One of the fastest ways is like so:
Select Cast(DateDiff(d, 0, DateColumn) As DateTime)
Thomas
"Charles Allen" <callen@.bkd.com> wrote in message
news:eoG6QeraFHA.1040@.TK2MSFTNGP10.phx.gbl...
> Is there an easy way to convert a datetime field to a date in a query? I w
ork
> with an ERP system that stores dates in datetime fields. All I need is the
> date portion.
> Thanks
>|||I weird and proprietary way:
CAST(CEILING(CAST(start_date AS FLOAT)) AS DATETIME))
The Standard syntax is EXTRACT (<temporal unit. FROM <temporal
expression> ), if you need to port code.|||>> CAST(CEILING(CAST(start_date AS FLOAT)) AS DATETIME))
I think CEILING will round up the FLOAT value giving the next day.
Anith
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment