Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
kiddoOnSQL
Starting Member
16 Posts |
Posted - 2011-05-29 : 22:27:42
|
| HelloI get a string with a date in it from a text file in this format "ddmmyyyy". This is stored in a nvarchar column type in my SQL table.I then have to pass this string to an existing function that calculates the week ending date from that date. This is that weekending function:ALTER FUNCTION [dbo].[GetWeekEndingDate](@CurrentDate datetime)RETURNS datetime ASBEGIN Declare @NewDate as DateTime set @NewDate = dateadd( day, ( 15 - (datepart( weekday, @CurrentDate ) + @@DateFirst )) % 7, @CurrentDate ) RETURN (Cast(Year(@Newdate) as varchar(4)) + '/' + Cast(Month(@Newdate) as VarChar(2)) + '/' + Cast(Day(@Newdate) as VarChar(2)))ENDGOI DONT want to change the week ending function, however the week ending function seems to accept my string parameter only if I pass it as 20110331 or 31 Mar 2011.How do I convert\format my original nvarchar type date string so that I can pass that to this function? |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-05-30 : 02:01:53
|
You can get it using SUBSTRING(). No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
jfarrugia
Yak Posting Veteran
55 Posts |
|
|
|
|
|