April 19, 2006 at 10:26 am
Hi all,
I am having issues when trying to truncate a DATETIME column using the SUBSTRING() function in a SELECT statement. I have tried using CAST and CONVERT functions on the DATETIME column but still get error messages. Is there another way of doing this?
SELECT SUBSTRING(CAST(date AS NVARCHAR(11), 1, 10)) FROM table
I am stumped with this
Hope you can help.
Tryst
April 19, 2006 at 10:35 am
What information are you trying to get from the DATETIME column?
April 19, 2006 at 10:40 am
For starters, get your close paren from the end of the expression to the end of the cast function...
SELECT SUBSTRING(CAST(date AS NVARCHAR(11)), 1, 10)
..and then explain (as pam asked) the requirements...
**ASCII stupid question, get a stupid ANSI !!!**
April 19, 2006 at 5:01 pm
Trys this instead...
SELECT CONVERT(VARCHAR(10),date,101)
... because the supbstring method on date castings will likely not five you the mm/dd/yyyy format that I think you're looking for. And here's some other formating style numbers you can sub for the 101...
yyyymmdd = 112
dd/mm/yyyy = 103
--Jeff Moden
Change is inevitable... Change for the better is not.
April 20, 2006 at 2:37 am
Hi, and thanks for the reply people.
I will attempt your solutions when I load up query analyer.
To answer Pam's question, I am trying to get the date from the datatime column (truncate the time part).
Thanks
Tryst
April 20, 2006 at 3:16 am
Thats sorted it.
Thanks Jeff (and all).
Tryst
April 20, 2006 at 8:16 pm
You bet... thank you for the feedback.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply