The following work if you need to end up with a varchar value:
select Left(cast(getdate() As Varchar(27)),11)
select convert(VARCHAR(8),getdate(),103)
If you need a centurydate, this works as above:
select cast(datepart(dd,getdate()) As Varchar(2)) + '/' +
cast(datepart(mm,getdate()) As Varchar(2)) + '/' +
cast(datepart(yyyy,getdate()) As Varchar(4))
In the USA the style parameter to Convert (103) will need change and you
might want to shuffle the casts in the final statement. Using the same
conversion routines in reverse, the returned values can be reconverted to
datetime vlues for midnight at the start ofthe respective dates. (I've used
getdate as a date expression for ease of demonstration - obviously it can be
whatever date expression you need it to be)
> -----Original Message-----
> From: James Habjanetz [SMTP:James.[Email Address Removed] Sent: Friday, July 12, 2002 12:06 PM
> To: [Email Address Removed] Subject: Date
>
> Hello,
> Does anyone know how to separate the 'whole date' from a datetime
> datatype. I have tried many ways but just cannot find the correct way.
>
> Thank You,
> James J. Habjanetz
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: mssqldba-[Email Address Removed] For additional commands, e-mail: mssqldba-[Email Address Removed]MS Sql Server LazyDBA home page