Tuesday, March 27, 2012

does sql have this...

Hey all,
does sql server have a date.parse function?
take 20050101
and
convert
1/1/2005
thanks,
rodcharRodchar,
Yes. See the CONVERT function with the optionaly style argument at:
CAST and CONVERT
http://msdn.microsoft.com/library/d...br />
2f3o.asp
Also may want to view the DATEPART function
http://msdn.microsoft.com/library/d...br />
2mic.asp
HTH
Jerry
"rodchar" <rodchar@.discussions.microsoft.com> wrote in message
news:24EC8B21-F17F-4992-BF25-D6632A46B98F@.microsoft.com...
> Hey all,
> does sql server have a date.parse function?
> take 20050101
> and
> convert
> 1/1/2005
> thanks,
> rodchar|||It's called CONVERT.
http://www.aspfaq.com/2464
Do you have a copy of Books Online?
"rodchar" <rodchar@.discussions.microsoft.com> wrote in message
news:24EC8B21-F17F-4992-BF25-D6632A46B98F@.microsoft.com...
> Hey all,
> does sql server have a date.parse function?
> take 20050101
> and
> convert
> 1/1/2005
> thanks,
> rodchar|||Having some trouble...
select convert(datetime,20050101,101)
do i need to use a combinatinon of Cast and Convert or something?
"Jerry Spivey" wrote:

> Rodchar,
> Yes. See the CONVERT function with the optionaly style argument at:
> CAST and CONVERT
> http://msdn.microsoft.com/library/d... />
o_2f3o.asp
> Also may want to view the DATEPART function
> http://msdn.microsoft.com/library/d... />
b_2mic.asp
> HTH
> Jerry
> "rodchar" <rodchar@.discussions.microsoft.com> wrote in message
> news:24EC8B21-F17F-4992-BF25-D6632A46B98F@.microsoft.com...
>
>|||> select convert(datetime,20050101,101)
You are trying to select an INT. A date is treated like a string in SQL
Server.
select convert(datetime, '20050101')
And using the 101 style parameter makes no sense here, unless you are going
to convert to a string in m/d/y format after you convert to datetime.
Do you have a copy of Books Online?
A|||Rodchar,
Enclose the date in single quotes and see the prior CONVERT link for the
date style.
HTH
Jerry
"rodchar" <rodchar@.discussions.microsoft.com> wrote in message
news:5A716BEE-2F33-4398-86B9-98C01E6B3A39@.microsoft.com...
> Having some trouble...
> select convert(datetime,20050101,101)
> do i need to use a combinatinon of Cast and Convert or something?
> "Jerry Spivey" wrote:
>|||select convert(varchar(10), '20050101', 101)
"rodchar" <rodchar@.discussions.microsoft.com> wrote in message
news:5A716BEE-2F33-4398-86B9-98C01E6B3A39@.microsoft.com...
> Having some trouble...
> select convert(datetime,20050101,101)
> do i need to use a combinatinon of Cast and Convert or something?
> "Jerry Spivey" wrote:
>|||> select convert(varchar(10), '20050101', 101)
when i try this, i still get 20050101 instead of 1/1/2005
"Raymond D'Anjou" wrote:

> select convert(varchar(10), '20050101', 101)
> "rodchar" <rodchar@.discussions.microsoft.com> wrote in message
> news:5A716BEE-2F33-4398-86B9-98C01E6B3A39@.microsoft.com...
>
>|||Hi,
Your date is already in char format, so the conversion makes no sense.
What are you trying to do?
If you have a datetime value you can use convert to display it as you wish.
Try:
select convert(varchar(10), GetDate(), 101)
HTH
Dan Artuso
"rodchar" <rodchar@.discussions.microsoft.com> wrote in message
news:EF7DE317-07ED-474A-83CE-E8D9F86FFEAB@.microsoft.com...
> when i try this, i still get 20050101 instead of 1/1/2005
> "Raymond D'Anjou" wrote:
>|||>> select convert(varchar(10), '20050101', 101)
> when i try this, i still get 20050101 instead of 1/1/2005
EGADS. Have you read anything in this thread? Do you have a copy of Books
Online?
SELECT CONVERT(CHAR(10), CONVERT(SMALLDATETIME, '20050101'), 101)
In any case, this is a really stupid format to present to users, IMHO. Do
any British people use your application? How about Canadians? To them, do
you think 7/6/2005 is July 6th or June 7th? Do you think they would agree
with you?
We have standards for a reason. Please consider using them.sql

No comments:

Post a Comment