dbTalk Databases Forums  

Convert CHAR YYYYMMDD to mm/dd/yyyy

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Convert CHAR YYYYMMDD to mm/dd/yyyy in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Tony Rogerson
 
Posts: n/a

Default Re: Convert CHAR YYYYMMDD to mm/dd/yyyy - 08-24-2007 , 09:39 AM






Quote:
Picky, picky, but the proper term is "ISO-8601 Standard" and the
Standard SQL format is "yyyy-mm-dd" from that Standard

I doubt I'll get an answer, but yyyy-??-?? don't work in SQL Server so why
do you keep telling people to use it?

select cast( '2007-04-01' as datetime )
select cast( '2007-04-01T00:00:00' as datetime )

Here in the UK in cloudy Harpenden with the default connection settings
gives these results....

-----------------------
2007-01-04 00:00:00.000

(1 row(s) affected)


-----------------------
2007-04-01 00:00:00.000

(1 row(s) affected)

Why do you keep telling people to use yyyy-mm-dd when you have been told
several times of this behaviour?

--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson
[Ramblings from the field from a SQL consultant]
http://sqlserverfaq.com
[UK SQL User Community]


"--CELKO--" <jcelko212 (AT) earthlink (DOT) net> wrote

Quote:
'YYYYMMDD' is one of the standard, non-regional formats supported by SQL
Server. No special conversion is necessary:

Picky, picky, but the proper term is "ISO-8601 Standard" and the
Standard SQL format is "yyyy-mm-dd" from that Standard



Reply With Quote
  #12  
Old   
Piero 'Giops' Giorgi
 
Posts: n/a

Default Re: Convert CHAR YYYYMMDD to mm/dd/yyyy - 08-24-2007 , 11:40 AM






On Aug 23, 5:13 pm, "rdraider" <rdrai... (AT) sbcglobal (DOT) net> wrote:

Quote:
Conversion necessary because the &%#%$&)# user wants to see mm/dd/yyyy
What the user wants and what the Db needs are two different things.
You must store the date as a standard and THEN, formatting the output,
you can write whatever you want.

But NOT in the DB

P



Reply With Quote
  #13  
Old   
rdraider
 
Posts: n/a

Default Re: Convert CHAR YYYYMMDD to mm/dd/yyyy - 08-24-2007 , 05:01 PM



Unfortunately I have no control over the format of the data in SQL nor the
application. I am however expected to please the users :-/
Time for a new job. I've always wanted to be a pilot...

Thanks for all the help.

RD

"Piero 'Giops' Giorgi" <giorgi.piero (AT) gmail (DOT) com> wrote

Quote:
On Aug 23, 5:13 pm, "rdraider" <rdrai... (AT) sbcglobal (DOT) net> wrote:

Conversion necessary because the &%#%$&)# user wants to see mm/dd/yyyy

What the user wants and what the Db needs are two different things.
You must store the date as a standard and THEN, formatting the output,
you can write whatever you want.

But NOT in the DB

P




Reply With Quote
  #14  
Old   
Eric J. Holtman
 
Posts: n/a

Default Re: Convert CHAR YYYYMMDD to mm/dd/yyyy - 08-24-2007 , 07:10 PM



"rdraider" <rdraider (AT) sbcglobal (DOT) net> wrote in
news:5xIzi.1664$vU4.326 (AT) nlpi068 (DOT) nbdc.sbc.com:

Quote:
Unfortunately I have no control over the format of the data in SQL nor
the application. I am however expected to please the users :-/

Well, if you can't control it in SQL, *or* in the application,
then you're well and truly fucked.




Reply With Quote
  #15  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Convert CHAR YYYYMMDD to mm/dd/yyyy - 08-25-2007 , 03:26 AM



rdraider (rdraider (AT) sbcglobal (DOT) net) writes:
Quote:
Unfortunately I have no control over the format of the data in SQL nor the
application. I am however expected to please the users :-/
Time for a new job. I've always wanted to be a pilot...
Yes, that's the point with returning the date as datetime. The client
settings takes full control, so that each user can get the date the way
he prefers.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #16  
Old   
--CELKO--
 
Posts: n/a

Default Re: Convert CHAR YYYYMMDD to mm/dd/yyyy - 08-26-2007 , 09:34 AM



Quote:
Here in the UK in cloudy Harpenden with the default connection settings gives these results...
That's funny -- here in sunny Austin I get the right answer with my
connection settings. Moral to the story "Think globally (i.e. ISO)
and act locally (i.e fix your dialect and proprietary setting)" to
paraphrase the Greens.



Reply With Quote
  #17  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Convert CHAR YYYYMMDD to mm/dd/yyyy - 08-26-2007 , 01:46 PM



--CELKO-- (jcelko212 (AT) earthlink (DOT) net) writes:
Quote:
Here in the UK in cloudy Harpenden with the default connection settings
gives these results...

That's funny -- here in sunny Austin I get the right answer with my
connection settings. Moral to the story "Think globally (i.e. ISO)
and act locally (i.e fix your dialect and proprietary setting)" to
paraphrase the Greens.
And think global means "if it works in where I am, it works"? I know
that it's hard to be humble if you are from Texas, but this is getting
out of hand.

Fact is, in SQL 2005 the format YYYY-MM-DD is subject to local settings
and cannot be trusted, ISO or not. Of course, it was a design made in
California, so I can understand that it's hard for you to swallow.

To soothe you, these two formats are safe:

YYYY-MM-DDThh:mm:ss
YYYY-MM-DDZ

And it seems that when you work with the new date and time data types in
SQL 2000, YYYY-MM-DD is always correctly interpreted.




--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #18  
Old   
Tony Rogerson
 
Posts: n/a

Default Re: Convert CHAR YYYYMMDD to mm/dd/yyyy - 08-27-2007 , 07:32 AM



Quote:
That's funny -- here in sunny Austin I get the right answer with my
connection settings. Moral to the story "Think globally (i.e. ISO)
and act locally (i.e fix your dialect and proprietary setting)" to
paraphrase the Greens.
I see, with YOUR regional settings it works - well that explains it all.

The rest of the planet should adopt Texas Regional settings I guess then.

Perhaps you should alter your statement about regional settings and people
letting the client sort it out then...

This issue is a good marker as to just how professional you really are; now
you know that use the date format YYYY-MM-DD cannot be trusted in SQL
Server, will you keep preaching the use of it?

Or will you use the ISO compliant YYYY-MM-DDT00:00:00 or YYYYMMDD instead?

I look forward to seeing that over the coming months.

--
Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson
[Ramblings from the field from a SQL consultant]
http://sqlserverfaq.com
[UK SQL User Community]



Reply With Quote
  #19  
Old   
Piero 'Giops' Giorgi
 
Posts: n/a

Default Re: Convert CHAR YYYYMMDD to mm/dd/yyyy - 08-29-2007 , 11:37 AM



On Aug 24, 3:01 pm, "rdraider" <rdrai... (AT) sbcglobal (DOT) net> wrote:

Quote:
I've always wanted to be a pilot...
I have my PPL (Private Pilot License) since 1982... :-)
You can't imagine how relaxing it is to go fly after a day in front of
the computer screen.

Only downside... damn expensive!!!

Anyway... do not compromise on the data format in the DB.
VERY wrong.

P



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.