Hi,
I'm trying to convert the last four numbers of the following string
SP1/84/056351/0406
to a date. It should default to the 31st of the month. In the above
case it would be 31st of April 2006. Anyone any ideas?
declare @.str varchar(20)
set @.str = 'SP1/84/056351/0406'
declare @.month varchar(2)
declare @.year varchar(2)
set @.year = right (@.str,2)
select @.month = substring (@.str, len(@.str)-3,2)
select @.month
select @.year
select dateadd(m,1, convert(datetime,@.year+@.month+'01')) - 1
Regards
Amish Shah
|||Thank you for the help Amish
Regards
Ross
|||Thank you for the help Amish
Regards
Ross
|||rosco wrote on 6 Mar 2006 02:24:13 -0800:
> Hi,
> I'm trying to convert the last four numbers of the following string
> SP1/84/056351/0406
> to a date. It should default to the 31st of the month. In the above
> case it would be 31st of April 2006. Anyone any ideas?
You want it to default to an invalid date? There are only 30 days in April.
Dan
Showing posts with label 0406to. Show all posts
Showing posts with label 0406to. Show all posts
Tuesday, March 27, 2012
date query
Hi,
I'm trying to convert the last four numbers of the following string
SP1/84/056351/0406
to a date. It should default to the 31st of the month. In the above
case it would be 31st of April 2006. Anyone any ideas?declare @.str varchar(20)
set @.str = 'SP1/84/056351/0406'
declare @.month varchar(2)
declare @.year varchar(2)
set @.year = right (@.str,2)
select @.month = substring (@.str, len(@.str)-3,2)
select @.month
select @.year
select dateadd(m,1, convert(datetime,@.year+@.month+'01')) - 1
Regards
Amish Shah|||Thank you for the help Amish
Regards
Ross|||Thank you for the help Amish
Regards
Ross|||rosco wrote on 6 Mar 2006 02:24:13 -0800:
> Hi,
> I'm trying to convert the last four numbers of the following string
> SP1/84/056351/0406
> to a date. It should default to the 31st of the month. In the above
> case it would be 31st of April 2006. Anyone any ideas?
You want it to default to an invalid date? There are only 30 days in April.
Dan
I'm trying to convert the last four numbers of the following string
SP1/84/056351/0406
to a date. It should default to the 31st of the month. In the above
case it would be 31st of April 2006. Anyone any ideas?declare @.str varchar(20)
set @.str = 'SP1/84/056351/0406'
declare @.month varchar(2)
declare @.year varchar(2)
set @.year = right (@.str,2)
select @.month = substring (@.str, len(@.str)-3,2)
select @.month
select @.year
select dateadd(m,1, convert(datetime,@.year+@.month+'01')) - 1
Regards
Amish Shah|||Thank you for the help Amish
Regards
Ross|||Thank you for the help Amish
Regards
Ross|||rosco wrote on 6 Mar 2006 02:24:13 -0800:
> Hi,
> I'm trying to convert the last four numbers of the following string
> SP1/84/056351/0406
> to a date. It should default to the 31st of the month. In the above
> case it would be 31st of April 2006. Anyone any ideas?
You want it to default to an invalid date? There are only 30 days in April.
Dan
Subscribe to:
Posts (Atom)