DateTime from concatenated string
-
Hi, I am trying to insert into a DateTime field by concatenating a string and a nVarChar field like so:
CONVERT(datetime, '1/1/' + tblMembershipRecords.[YearJoined], 103)
But I get a message stating; 'Conversion failed when converting datetime from character string.' Any ideas what is going wrong?
-
Hi, I am trying to insert into a DateTime field by concatenating a string and a nVarChar field like so:
CONVERT(datetime, '1/1/' + tblMembershipRecords.[YearJoined], 103)
But I get a message stating; 'Conversion failed when converting datetime from character string.' Any ideas what is going wrong?
Liqz wrote:
Any ideas what is going wrong?
The computer tries to "interpret" your string as a date, and it doesn't understand it. It seems that it expects the date to be in a different format. Try something like this;
SELECT DATEADD(y, tblMembershipRecords.[YearJoined], getdate())
That will add a single year to the
DateTime
, without converting it to a string.I are Troll :)
-
Liqz wrote:
Any ideas what is going wrong?
The computer tries to "interpret" your string as a date, and it doesn't understand it. It seems that it expects the date to be in a different format. Try something like this;
SELECT DATEADD(y, tblMembershipRecords.[YearJoined], getdate())
That will add a single year to the
DateTime
, without converting it to a string.I are Troll :)
Got it, thanks for the tip, all working now :)