SirDrinksalot
Programmer
Hi all,
I have a wee problem which hopefully someone can help me with. I have a datetime field with the format dd/mm/yyyy hh:mm:ss, and i need to extract the date part only, but also rearrange it so that it is of format YYMMDD. This i have achieved by using the convert and datepart functions. However, as a result of this, the date returned is now in a varchar format. Unfortunately the client wants the return value to be of type Datetime - is this possible?
To help anyone who's interested, here is the code i ave currently written:
(Select
right(convert(varchar(4),datepart(year,inf.feature_insp_date)),2)
+ (case len(datepart(month,inf.feature_insp_date))
when 1 then '0' else '' end) + convert(varchar(2),datepart(month,inf.feature_insp_date))
+ (case len(datepart(day,inf.feature_insp_date))
when 1 then '0' else '' end) + convert(varchar(2),datepart(day,inf.feature_insp_date))
from engineer.inspection_feature inf
where inf.plot_number = def.plot_number) as inspection_date,
Hopefully someone can see through the haze and open my eyes!
I have a wee problem which hopefully someone can help me with. I have a datetime field with the format dd/mm/yyyy hh:mm:ss, and i need to extract the date part only, but also rearrange it so that it is of format YYMMDD. This i have achieved by using the convert and datepart functions. However, as a result of this, the date returned is now in a varchar format. Unfortunately the client wants the return value to be of type Datetime - is this possible?
To help anyone who's interested, here is the code i ave currently written:
(Select
right(convert(varchar(4),datepart(year,inf.feature_insp_date)),2)
+ (case len(datepart(month,inf.feature_insp_date))
when 1 then '0' else '' end) + convert(varchar(2),datepart(month,inf.feature_insp_date))
+ (case len(datepart(day,inf.feature_insp_date))
when 1 then '0' else '' end) + convert(varchar(2),datepart(day,inf.feature_insp_date))
from engineer.inspection_feature inf
where inf.plot_number = def.plot_number) as inspection_date,
Hopefully someone can see through the haze and open my eyes!