| Return To Topics |
Originally Posted: 6/6/2006 6:24:45 PM |
| |
Last Updated: 6/6/2006 6:24:45 PM |
Subject:
Date Parsing using Transact SQL
You Asked....
How do I covert a date in the string format 19960303 to a date?
and we responded....
I went around and around with this one when I first started programming T-SQL.
Try this it should work.
SELECT CONVERT(smalldatetime,'19960303',112)
Review By: naka55
The style parmater on the CONVERT is not necessary. It's only needed when you want to convert to a specific format
>>>>>Begin Original Message<<<<<
How do I covert a date in the string format 19960303 to a date?
>>>>>End Original Message<<<<<
Review On: 6/6/2006 6:51:39 PM
Review By: Gary
>>>>>Begin Original Message<<<<<
How do I covert a date in the string format 19960303 to a date?
>>>>>End Original Message<<<<<
You can also use CAST such as:
CAST('1996030' AS smalldatetime)
or
CAST('19960303' AS datetime)
Review On: 6/9/2006 3:07:32 AM
Review By: Tina Bhate
>>>>>Begin Original Message<<<<<
How do I covert a date in the string format 19960303 to a date?
>>>>>End Original Message<<<<<
Hello Friends,
Yes, by using CAST function you can get the output.
BUT if we you CONVERT then we can specify the format means 112 is a particular format for data type...so is 106.
CONVERT is most recommended and oftenly used in case of DATE.
Review On: 6/13/2006 4:25:00 PM
|