|
Home > Archive > MS SQL Server > March 2006 > date query
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| 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,@ye
ar+@month+'01')) - 1
Regards
Amish Shah
| |
|
| Thank you for the help Amish
Regards
Ross
| |
|
| Thank you for the help Amish
Regards
Ross
| |
| Daniel Crichton 2006-03-06, 7:15 pm |
| 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
|
|
|
|
|