June 16, 2010 at 8:36 am
Hi I have a date in varchar(yyyy/mm/dd)
I need to convert to datetime in the format mm/dd/yyyy
can u suggest me any thing
I am using the convert(datetime,ItemDate,101 ) but i'm not able to.
Thanks in advance
June 16, 2010 at 8:47 am
DECLARE @date AS VARCHAR(10)
SET @date = '2010/01/29'
SELECT CONVERT(VARCHAR(10), (CONVERT(DATETIME, @date)), 101)
--OUTPUT -> "01/29/2010"
??
June 16, 2010 at 9:01 am
I need that to be in datetime only
and change the format
June 16, 2010 at 10:11 am
to convert string YYYY/MM/DD (which is close to safe ISO8601 format) into datetime you don't need anything other than:
SET DATEFORMAT ymd
DECLARE @date AS VARCHAR(10)
SET @date = '2010/01/29'
SELECT CONVERT(DATETIME, @date)
"SET DATEFORMAT ymd" will not be required if your default DATEFORMAT is not dmy. Also, values in ISO or ISO8601 format are safe to be converted into datetime independently of the DATEFORMAT settings.
Now, about having or storing the datetime in a particular format:
IT IS IMPOSSIBLE!
Or better to say is not a correct request.
The DATETIME is a DATETIME.
When you are talking about "I want datetime in a specific format" - you are talking about string representation of a datetime for display purposes. Check options for CONVERT function to see in which format you can output DATETIME values in SQL Server.
Without specific format, when you select a DATETIME, it will be formatted as per default which is "mon dd yyyy hh:miAM (or PM)" (its depends on your locale and database language settings which can be changed).
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply