I can't seem to find a method of converting a CHAR(8) column in the form of
YYYYMMDD to an actual date such as mm/dd/yyyy
Can anyone point me in the right direction?
Thanks 17 69868
Correction the source field in an INT type
So how to convert INT type YYYYMMDD to a date mm/dd/yyyy
"rdraider" <rd******@sbcglobal.netwrote in message
news:7U*****************@newssvr25.news.prodigy.ne t...
>I can't seem to find a method of converting a CHAR(8) column in the form of YYYYMMDD to an actual date such as mm/dd/yyyy
Can anyone point me in the right direction?
Thanks
"rdraider" <rd******@sbcglobal.netwrote in message
news:7U*****************@newssvr25.news.prodigy.ne t...
>I can't seem to find a method of converting a CHAR(8) column in the form of YYYYMMDD to an actual date such as mm/dd/yyyy
Can anyone point me in the right direction?
Thanks
'YYYYMMDD' is one of the standard, non-regional formats supported by SQL
Server. No special conversion is necessary:
DECLARE @dt CHAR(8);
SET @dt = '20070823';
SELECT CAST(@dt AS DATETIME) AS dt;
dt
------------------------------------------------------
2007-08-23 00:00:00.000
(1 row(s) affected)
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online: http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--
"rdraider" <rd******@sbcglobal.netwrote in message
news:5_*****************@newssvr25.news.prodigy.ne t...
Correction the source field in an INT type
So how to convert INT type YYYYMMDD to a date mm/dd/yyyy
DECLARE @dt INT;
SET @dt = 20070823;
SELECT CAST(CAST(@dt AS CHAR(8)) AS DATETIME) AS dt;
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online: http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--
Thanks David.
I know how to generate CREATE TABLE scripts but is there a fast way to
generate INSERT statements for the actual data?
"David Portas" <RE****************************@acm.orgwrote in message
news:PZ******************************@giganews.com ...
"rdraider" <rd******@sbcglobal.netwrote in message
news:5_*****************@newssvr25.news.prodigy.ne t...
>Correction the source field in an INT type So how to convert INT type YYYYMMDD to a date mm/dd/yyyy
DECLARE @dt INT;
SET @dt = 20070823;
SELECT CAST(CAST(@dt AS CHAR(8)) AS DATETIME) AS dt;
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online: http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--
>>'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 :)
Conversion necessary because the &%#%$&)# user wants to see mm/dd/yyyy
Thanks
"--CELKO--" <jc*******@earthlink.netwrote in message
news:11**********************@e9g2000prf.googlegro ups.com...
>>>'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 :)
>Conversion necessary because the &%#%$&)# user wants to see mm/dd/yyyy <<
Then do it in the front end like you are supposed to in ANY tiered
architecture; 1NF, basic Software Engineering and all that jazz ...
"rdraider" <rd******@sbcglobal.netwrote in message
news:Vo****************@newssvr29.news.prodigy.net ...
Conversion necessary because the &%#%$&)# user wants to see mm/dd/yyyy
Thanks
Well I assumed that you were storing the date as a DATETIME. What my
suggestion does is to convert a string or integer to a DATETIME. DATETIME
has NO format. So if the user wants to see it formatted some particular way
you must do that in the client application, not in SQL Server. SQL Server
has no control over how the date is displayed.
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online: http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--
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--" <jc*******@earthlink.netwrote in message
news:11**********************@e9g2000prf.googlegro ups.com...
>>>'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 :)
On Aug 23, 5:13 pm, "rdraider" <rdrai...@sbcglobal.netwrote:
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
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" <gi**********@gmail.comwrote in message
news:11**********************@m37g2000prh.googlegr oups.com...
On Aug 23, 5:13 pm, "rdraider" <rdrai...@sbcglobal.netwrote:
>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
>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.
--CELKO-- (jc*******@earthlink.net) writes:
>>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, es****@sommarskog.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
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]
On Aug 24, 3:01 pm, "rdraider" <rdrai...@sbcglobal.netwrote:
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brad Moore |
last post by:
Hey all,
I'm getting the following compiler error from my code. I was wondering
if anyone could help me understand the concept behind it (I actually did
try and compile this degenerate...
|
by: MilanB |
last post by:
Hello
How to convert char to int?
Thanks
|
by: Joah Senegal |
last post by:
Hello I need to convert a chat to a string... but I don't know how to do
this. i;ve searched the internet but I've only find some code to convert
char * to string or char to string....
but I...
|
by: simon |
last post by:
I am a fresh Visual C++ .NET Developer. Can you kindly guide me for
How to Convert char to System::String
I am using windows forms and trying to set a text value referencing
the method...
|
by: rdraider |
last post by:
I can't seem to find a way to convert an INT type in the form of YYYYMMDD to
an actual date form of mm/dd/yyyy
Can anyone pointt me in the right direction?
Thanks
|
by: Ashraf Ansari |
last post by:
Hi,
How Can I convert MM/dd/yyyy format into dd/MM/yyyy and the date
which is converted into dd/MM/yyyy should be in DateTime format. I do
not want to store it as a string.
Please help
...
|
by: Rasheed |
last post by:
Hi,
i have a char pointer buffer which will hold the bitmap buffer, So i
need to convert char *buffer as a bitmap.
becuase when i draw on the Dialog using char *buffer. Nothing will be
dispalyed....
|
by: mamul |
last post by:
Hi please some one can help me. how to convert char * to string?
i have take char *argv from command line and want to pass to a function as string object(string str)
i want to first convert argv...
|
by: Lagon666 |
last post by:
Is any solution to convert "1055901520" to yyyy/mm/dd:
$date = getdate();
print $date; // return 1055901520
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |