August 21, 2006 at 2:40 pm
Hi,
Is there a way to convert VARCHAR to DataType to DateTime
Eg: Select CAST('22/10/2007' AS DateTime)
Thanks
Jack
August 21, 2006 at 2:48 pm
CAST OR CONVERT Can be used
DECLARE @AA VARCHAR(25)
SET @AA = '01/01/2006'
IF ISDATE(@AA) = 1
SELECT CONVERT(DATETIME, @AA) AADate
ELSE
PRINT 'Not Valid Date'
SET @AA = '01/01/20062'
IF ISDATE(@AA) = 1
SELECT CONVERT(DATETIME, @AA) AADate
ELSE
PRINT 'Not Valid Date'
Regards,
gova
August 21, 2006 at 2:52 pm
Thanks Buddy that helps.. Appreciate your quick response too.
August 23, 2006 at 12:30 am
Jack,
It appears that you want to convert the dd/mm/yyyy format in which case, the examples posted, so far, will reject a large portion of your dates. If that's true, then try this, instead...
SELECT CONVERT(DATETIME,somedatecol,103)
FROM sometable
"103" is the dd/mm/yyyy format for CONVERT...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply