Showing posts with label datetime. Show all posts
Showing posts with label datetime. Show all posts

Tuesday, March 20, 2012

change datetime to date

I have a datetime field (example: 08/06/2007 9:05:06AM) that I want to change so only the date is in a select statement (so I only get 08/06/2007). How do I write the expression?
Help is appreciated.
Thanksthere is no good way that i know of to do this in ANSI SQL

which database are you using?|||Thanks for posting to my thread. I found a workaround (even though it ain't pretty) but it's working so thanks again for posting.|||what was your workaround?

change date&time default formate to mm/dd/yyyy

dear

i've an old sql server 2000, with default date format mm/dd/yyyy

i've installed a new one SQL server 2005 , my application did't work with its date format

i wan't to change SQL 2005 default date format to mm/dd/yyyy instead of dd/mm/yyyy

regards

Dates are displayed as configured for the user (its a session setting). But formatting of the dates should be made in the front end / presentation layer. Don′t do that on the server, try to pass the date in a more generic format like ISO Date. 20061114

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

Monday, March 19, 2012

Change Data type from Nvarchar to datetime

i have a sql db in production and i need to change the data type of one of m
y
fields. Can this be done? I have made several attempts but have failed.Probably because you have data in there that is not a valid datetime. This
is a common symptom for using a catch-all datatype like nvarchar for storing
inappropriate data, whether it be to ease the development/validation of end
user interfaces or to seamlessly integrate legacy data.
"Failed" could mean many things to me. Are you just saying ALTER TABLE
tablename ALTER COLUMN columnname DATETIME? If so, and that fails due to a
conversion issue, then you may want to consider trying this:
-- how many are bad:
SELECT COUNT(*) FROM TableName WHERE IsDate(ColumnName)=0;
-- a few samples:
SELECT TOP 50 ColumnName FROM TableName WHERE ISDate(ColumnName)=0;
You might be really hosed, or you my just have to tweak the data before
altering the table, by converting to a valid datetime format. It's tough to
get any more specific without valid DDL and sample data (see
http://www.aspfaq.com/5006
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:6BB5D430-FFF8-4BC9-BF59-DA27B3B83615@.microsoft.com...
>i have a sql db in production and i need to change the data type of one of
>my
> fields. Can this be done? I have made several attempts but have failed.|||Thank you for your suggestion. However, I do not have any data in this
particular field. This is the error I get...
'Contacts' table
- Warning: Data might be lost converting column 'MaritalStatus' from
'nvarchar(20)'.
The MaritalStatus field does not have any data. I would like to rename it
to PromoCodeEmail and change the data type to datetime.
"Aaron Bertrand [SQL Server MVP]" wrote:

> Probably because you have data in there that is not a valid datetime. Thi
s
> is a common symptom for using a catch-all datatype like nvarchar for stori
ng
> inappropriate data, whether it be to ease the development/validation of en
d
> user interfaces or to seamlessly integrate legacy data.
> "Failed" could mean many things to me. Are you just saying ALTER TABLE
> tablename ALTER COLUMN columnname DATETIME? If so, and that fails due to
a
> conversion issue, then you may want to consider trying this:
> -- how many are bad:
> SELECT COUNT(*) FROM TableName WHERE IsDate(ColumnName)=0;
> -- a few samples:
> SELECT TOP 50 ColumnName FROM TableName WHERE ISDate(ColumnName)=0;
> You might be really hosed, or you my just have to tweak the data before
> altering the table, by converting to a valid datetime format. It's tough
to
> get any more specific without valid DDL and sample data (see
> http://www.aspfaq.com/5006
>
>
>
>
> "Joe" <Joe@.discussions.microsoft.com> wrote in message
> news:6BB5D430-FFF8-4BC9-BF59-DA27B3B83615@.microsoft.com...
>
>|||Joe,
First, thats a warning, not an error. The warning is generated because
changing data types can result in loss of data, but that doesn't necessarily
mean they will.
Second, if you have a column that is not used, drop the column and add a new
column. There is no need to rename it and change the data type.
You are best off using a script for these changes rather than using the gui.
Scripts can be run against your development and test databases and debugged
before runnign them against production. Scripts also insure that the
changes made in all databases are the same, without having to worry about
user error from clicking on the wrong field in enterprise manager.
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:82D1F9C5-9AF9-4D3E-AC46-886F0E64CB4B@.microsoft.com...
> Thank you for your suggestion. However, I do not have any data in this
> particular field. This is the error I get...
> 'Contacts' table
> - Warning: Data might be lost converting column 'MaritalStatus' from
> 'nvarchar(20)'.
> The MaritalStatus field does not have any data. I would like to rename it
> to PromoCodeEmail and change the data type to datetime.
> "Aaron Bertrand [SQL Server MVP]" wrote:
>
This
storing
end
to a
tough to
of
failed.|||I have never written a script before. Is there some literature that will
assist me in doing you suggested?
"Aaron Bertrand [SQL Server MVP]" wrote:

> Probably because you have data in there that is not a valid datetime. Thi
s
> is a common symptom for using a catch-all datatype like nvarchar for stori
ng
> inappropriate data, whether it be to ease the development/validation of en
d
> user interfaces or to seamlessly integrate legacy data.
> "Failed" could mean many things to me. Are you just saying ALTER TABLE
> tablename ALTER COLUMN columnname DATETIME? If so, and that fails due to
a
> conversion issue, then you may want to consider trying this:
> -- how many are bad:
> SELECT COUNT(*) FROM TableName WHERE IsDate(ColumnName)=0;
> -- a few samples:
> SELECT TOP 50 ColumnName FROM TableName WHERE ISDate(ColumnName)=0;
> You might be really hosed, or you my just have to tweak the data before
> altering the table, by converting to a valid datetime format. It's tough
to
> get any more specific without valid DDL and sample data (see
> http://www.aspfaq.com/5006
>
>
>
>
> "Joe" <Joe@.discussions.microsoft.com> wrote in message
> news:6BB5D430-FFF8-4BC9-BF59-DA27B3B83615@.microsoft.com...
>
>|||What part of my suggestion are you having difficulty with?
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:356065F7-EB6A-4304-9448-ECF8B0FB40F7@.microsoft.com...
>I have never written a script before. Is there some literature that will
> assist me in doing you suggested?
> "Aaron Bertrand [SQL Server MVP]" wrote:
>

Sunday, March 11, 2012

Change column from datetime to int

I want to change a column from datetime to int. I'm using this T-SQL:
ALTER TABLE WebPages
ALTER COLUMN EndDate int;
I get this result:
Server: Msg 260, Level 16, State 1, Line 1
Disallowed implicit conversion from data type datetime to data type int,
table 'gIQInternetMaster.dbo.WebPages', column 'EndDate'. Use the CONVERT
function to run this query.
If I use Enterprise Manager the change happens without error. However, I
need to do this conversion as part of a larger script so I need to do it in
code. Can anyone tell me what EM is doing behind the scenes that allows this
to succeed? Thank you!Hi Ron
Please always state what version you are using.
I assume you are using SQL 2000 since you referred to Enterprise Manager. If
you trace what SQL Server is doing when you change datetime to int in EM,
you will see that it is actually recreating the entire table, selecting from
the old table using convert for the EndDate column, inserting into a new
table, dropping the original table and renaming the new table to the old
name. All indexes and triggers need to be rebuilt. This can be quite a
time-consuming process for a large table, but it is do-able. Just not with a
single statement.
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"Ron Hinds" < __ron__dontspamme@.wedontlikespam_garagei
q.com> wrote in message
news:%23LP8GFhVHHA.2212@.TK2MSFTNGP02.phx.gbl...
>I want to change a column from datetime to int. I'm using this T-SQL:
> ALTER TABLE WebPages
> ALTER COLUMN EndDate int;
> I get this result:
> Server: Msg 260, Level 16, State 1, Line 1
> Disallowed implicit conversion from data type datetime to data type int,
> table 'gIQInternetMaster.dbo.WebPages', column 'EndDate'. Use the CONVERT
> function to run this query.
> If I use Enterprise Manager the change happens without error. However, I
> need to do this conversion as part of a larger script so I need to do it
> in
> code. Can anyone tell me what EM is doing behind the scenes that allows
> this
> to succeed? Thank you!
>
>

Change column from datetime to int

I want to change a column from datetime to int. I'm using this T-SQL:
ALTER TABLE WebPages
ALTER COLUMN EndDate int;
I get this result:
Server: Msg 260, Level 16, State 1, Line 1
Disallowed implicit conversion from data type datetime to data type int,
table 'gIQInternetMaster.dbo.WebPages', column 'EndDate'. Use the CONVERT
function to run this query.
If I use Enterprise Manager the change happens without error. However, I
need to do this conversion as part of a larger script so I need to do it in
code. Can anyone tell me what EM is doing behind the scenes that allows this
to succeed? Thank you!
Hi Ron
Please always state what version you are using.
I assume you are using SQL 2000 since you referred to Enterprise Manager. If
you trace what SQL Server is doing when you change datetime to int in EM,
you will see that it is actually recreating the entire table, selecting from
the old table using convert for the EndDate column, inserting into a new
table, dropping the original table and renaming the new table to the old
name. All indexes and triggers need to be rebuilt. This can be quite a
time-consuming process for a large table, but it is do-able. Just not with a
single statement.
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"Ron Hinds" <__ron__dontspamme@.wedontlikespam_garageiq.com> wrote in message
news:%23LP8GFhVHHA.2212@.TK2MSFTNGP02.phx.gbl...
>I want to change a column from datetime to int. I'm using this T-SQL:
> ALTER TABLE WebPages
> ALTER COLUMN EndDate int;
> I get this result:
> Server: Msg 260, Level 16, State 1, Line 1
> Disallowed implicit conversion from data type datetime to data type int,
> table 'gIQInternetMaster.dbo.WebPages', column 'EndDate'. Use the CONVERT
> function to run this query.
> If I use Enterprise Manager the change happens without error. However, I
> need to do this conversion as part of a larger script so I need to do it
> in
> code. Can anyone tell me what EM is doing behind the scenes that allows
> this
> to succeed? Thank you!
>
>

Change column from datetime to int

I want to change a column from datetime to int. I'm using this T-SQL:
ALTER TABLE WebPages
ALTER COLUMN EndDate int;
I get this result:
Server: Msg 260, Level 16, State 1, Line 1
Disallowed implicit conversion from data type datetime to data type int,
table 'gIQInternetMaster.dbo.WebPages', column 'EndDate'. Use the CONVERT
function to run this query.
If I use Enterprise Manager the change happens without error. However, I
need to do this conversion as part of a larger script so I need to do it in
code. Can anyone tell me what EM is doing behind the scenes that allows this
to succeed? Thank you!Hi Ron
Please always state what version you are using.
I assume you are using SQL 2000 since you referred to Enterprise Manager. If
you trace what SQL Server is doing when you change datetime to int in EM,
you will see that it is actually recreating the entire table, selecting from
the old table using convert for the EndDate column, inserting into a new
table, dropping the original table and renaming the new table to the old
name. All indexes and triggers need to be rebuilt. This can be quite a
time-consuming process for a large table, but it is do-able. Just not with a
single statement.
--
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"Ron Hinds" <__ron__dontspamme@.wedontlikespam_garageiq.com> wrote in message
news:%23LP8GFhVHHA.2212@.TK2MSFTNGP02.phx.gbl...
>I want to change a column from datetime to int. I'm using this T-SQL:
> ALTER TABLE WebPages
> ALTER COLUMN EndDate int;
> I get this result:
> Server: Msg 260, Level 16, State 1, Line 1
> Disallowed implicit conversion from data type datetime to data type int,
> table 'gIQInternetMaster.dbo.WebPages', column 'EndDate'. Use the CONVERT
> function to run this query.
> If I use Enterprise Manager the change happens without error. However, I
> need to do this conversion as part of a larger script so I need to do it
> in
> code. Can anyone tell me what EM is doing behind the scenes that allows
> this
> to succeed? Thank you!
>
>

Sunday, February 12, 2012

Casting or Converting Smallint datatype to Datetime

A SQL Server 2005 db has three date related-columns (MonthGiven,DayGiven, YearGiven) each as smallint datatype. I would like tocreate a DocDate column (datetime datatype) that combines the data fromthe three existing date-related columns. I have tried casting andsimple concatentation without success.

ALTER TABLE Details ADD DocDate DateTime NULL

UPDATE Details SET DocDate = CAST(MonthGiven AS DateTime)+ '/' + CAST(DayGiven AS DateTime) + "/" Cast(YearGiven As DateTime)

I think I need to be doing a Conversion instead of casting buthave been unable to implement info I have found in the SQL ServerDeveloper Center in my situation.

I think this should work, it works for me

UPDATE Details SET DocDate = CAST(MonthGiven AS Varchar)+ '/' + CAST(DayGiven AS Varchar) +'/' +Cast(YearGiven As Varchar)


|||

You can also use

UPDATE Details SET DocDate = CONVERT(DateTime, CAST(MonthGiven AS Varchar)+ '/' + CAST(DayGiven AS Varchar) +'/' +Cast(YearGiven As Varchar), 101)

The last parameter (style) will change based on the input string to convert

http://msdn2.microsoft.com/en-us/library/ms187928.aspx


|||

Thanks for your prompt suggestions. I tried both and got the same error message:

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Sinceboth produced the same error, I must assume that either Imisrepresented my data or there is something within the data itselfthat is producing the error. I rechecked the datatypes, etc of myoriginal post and think that is ok.

I queried the data: SELECT MonthGiven, DayGiven, YearGiven FROM Details

When a month, day, or year is unknown the data value = 0

Iam guessing that is causing the error. If so, should i replacethose values with NULL or a string of 0s (Month = 00, Day = 00, Year =0000)?

Thanks again for your input and any further assistance you can provide.

|||

To handle the null values, you can add a where clause to the update statement (add extra conditions in case other illegal values are expected)

Update ...
where MonthGiven is not null and DayGiven is not null and YearGiven is not null

|||

Prashant,

Here is my TSQL:

ALTER TABLE Details ADD DocDate DateTime NULL

UPDATE Details SET DocDate = CONVERT(DateTime, CAST(MonthGiven ASVarchar)+ '/' + CAST(DayGiven AS Varchar) + '/' + Cast(YearGivenAs Varchar), 101) WHERE MonthGiven is not null and DayGiven isnot null and YearGiven is not null

Here is the error:

Conversion failed when converting datetime from character string.

|||

vish4forum:

I think this should work, it works for me

UPDATE Details SET DocDate = CAST(MonthGiven AS Varchar)+ '/' + CAST(DayGiven AS Varchar) +'/' +Cast(YearGiven As Varchar)

I think you can modify your table this way:

decare @.time varchar(100)

set @.time=CAST(MonthGiven AS Varchar)+ '/' + CAST(DayGiven AS Varchar) +'/' +Cast(YearGiven As Varchar)

update details set docdate=convert(datetime,@.time)

This should work well.

Hope my suggestion helps

|||

Hi B.C.,

I corrected spelling of declare and ran your query with this result:

Msg 207, Level 16, State 1, Line 3
Invalid column name 'MonthGiven'.
Msg 207, Level 16, State 1, Line 3
Invalid column name 'DayGiven'.
Msg 207, Level 16, State 1, Line 3
Invalid column name 'YearGiven'.

|||

I am trying another approach which may simplify this problem.

ALTER TABLE Details ADD DocDate varchar(20) NULL

UPDATE Details SET DocDate = CAST(MonthGiven AS VARCHAR(5) )+ '/' +CAST(DayGiven AS VARCHAR(5)) + '/' + CAST(YearGiven AS VARCHAR(5))

Sonow I have a DocDate column in the Details table with varchar data(e.g., 9/12/2007)) that simply needs to be cast as datetime. Howcan I do that?

|||

This query executed successfully, but in Object Explorer the data incolumn DocDate still shows as VarChar(20) after refreshing thetable.

UPDATE Details SET DocDate=CONVERT(Datetime,101)

Iwas expecting it to be datetime. Any thoughts on why the queryexecuted successfully but the datatype did not change in ObjectExplorer?

|||

Hi moonshadow,

My fault. The solution i gave above is wrong. You cannot use a intermedia variable in this case.

You can try the suggestionPrashant Kumar provided above. That should work. And as to your question, "UPDATE Details SET DocDate=CONVERT(Datetime,101)

I was expecting it to be datetime " , you cannot do that-- the string which you want to convert to datetime must follow a certain format, for example, 9/12/2007 or 2007-9-12. Based on my understanding, i think convert 101 to datetime value dosn't make sense.The right format is : convert(datetime, '9/12/2007') after which you will get a datetime value.

I would suggest you reading some materials on sql datetime. You will find that's very helpful to solve your problem. thanks

|||

Thanks to all for your patience and very helpful advice.

Cast Question - Converting Datetime into Date

Hi guys,
I knew that the Function Cast can do this but I tried a lot and I dont want to use the MONTH, YEAR, DAY function.

I have a smalldatetime field with a value of this 12/18/2004 4:02:00 PM
I just like to see it like this 12/18/2004

Hope you can help me up. Thanks.
-vinceSELECT CONVERT(varchar(10),GetDate(),101)

Got Books Online (BOL)?|||declare @.val datetime
set @.val='12/18/2005 11:00:00'
select @.val, convert(char(10),@.val,101)|||SELECT CONVERT(varchar(10),GetDate(),101)

Got Books Online (BOL)?

I have it here.. Thanks a lot...Sometimes, when you have a lot of things in your mind, you cant see exactly the answer which is sometimes in your face already. ;)

hehehe

cast or convert varchar to money/datetime

Hello,
I have a dataset that is all varchar with leading and
trailing spaces (comes from a mainframe). I import this
data to a table that is all varchar (using DTS). I then
insert it to a table that has the correct datatype fields,
but I have to perform a conversion. I have been using
Cast(ltrim(rtrim(colx)) As datetime)
Cast(ltrim(rtrim(colx)) As money)
I seem to be getting the correct data with datetime, and
with money I get like 306.6900. Am I supposed to get a $
symbol for money? Or just decimal? So is cast the
correct operator here or should I use convert? If
convert - how do I convert money?
Thanks,
RonThere is no reason to store the dollar sign with the numeric value, nor is
there a need to use the MONEY data type. In fact, this can cause problems.
See http://www.aspfaq.com/2503 which, among other things, describes reasons
to use DECIMAL in favor of MONEY/SMALLMONEY.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Ron" <anonymous@.discussions.microsoft.com> wrote in message
news:0b3601c53611$48d3c830$a401280a@.phx.gbl...
> Hello,
> I have a dataset that is all varchar with leading and
> trailing spaces (comes from a mainframe). I import this
> data to a table that is all varchar (using DTS). I then
> insert it to a table that has the correct datatype fields,
> but I have to perform a conversion. I have been using
> Cast(ltrim(rtrim(colx)) As datetime)
> Cast(ltrim(rtrim(colx)) As money)
> I seem to be getting the correct data with datetime, and
> with money I get like 306.6900. Am I supposed to get a $
> symbol for money? Or just decimal? So is cast the
> correct operator here or should I use convert? If
> convert - how do I convert money?
> Thanks,
> Ron|||SQL Server stores data, not the presentation of data. The client application
is what is doing the
presentation of your data. for the money datatype, the values 306.6900 and 3
06.69 are the same.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Ron" <anonymous@.discussions.microsoft.com> wrote in message
news:0b3601c53611$48d3c830$a401280a@.phx.gbl...
> Hello,
> I have a dataset that is all varchar with leading and
> trailing spaces (comes from a mainframe). I import this
> data to a table that is all varchar (using DTS). I then
> insert it to a table that has the correct datatype fields,
> but I have to perform a conversion. I have been using
> Cast(ltrim(rtrim(colx)) As datetime)
> Cast(ltrim(rtrim(colx)) As money)
> I seem to be getting the correct data with datetime, and
> with money I get like 306.6900. Am I supposed to get a $
> symbol for money? Or just decimal? So is cast the
> correct operator here or should I use convert? If
> convert - how do I convert money?
> Thanks,
> Ron|||Ron,
[money] values are numbers. 306.6900 is a number. The $ symbol
is not part of a money value, but just something that may be part of the
display of a number. SQL Server can convert money values to
strings with $ or with commas, using CONVERT with format codes
(see CAST AND CONVERT in Books Online).
The type of Cast(whatever as money) will definitely be [money]. If
you want to be absolutely sure, try
select cast(whatever as money) as onlyColumn
into #checktype
then look at the table structure for #checktype.
Steve Kass
Drew University
Ron wrote:

>Hello,
>I have a dataset that is all varchar with leading and
>trailing spaces (comes from a mainframe). I import this
>data to a table that is all varchar (using DTS). I then
>insert it to a table that has the correct datatype fields,
>but I have to perform a conversion. I have been using
>Cast(ltrim(rtrim(colx)) As datetime)
>Cast(ltrim(rtrim(colx)) As money)
>I seem to be getting the correct data with datetime, and
>with money I get like 306.6900. Am I supposed to get a $
>symbol for money? Or just decimal? So is cast the
>correct operator here or should I use convert? If
>convert - how do I convert money?
>Thanks,
>Ron
>

cast from string to DateTime type

HI I am using a C++ builder routine that fills a datacontrol from the result
s
of a query. Just wondering if there is a way to cast from string type to
DateTime as the data is on a Microsoft SQL 2000 server, would like to perfor
m
the cast in the query?
Thanks
--
Paul G
Software engineer.There are two T-SQL functions CAST and CONVERT which you use for type
conversions. SQL Server Books Online has all the details and examples for
using them.
Anith|||Hi thanks for the response, I tried the code below but get the error
missing operator in query expression Cast(StartTime as DateTime)="3/03/2005
"
StartTime is a string column in a table that looks like "3/03/2005 10:11:45"
Select * from tablename
WHERE CAST(StartTime AS DateTime)= "3/03/2005 12:12:00"
"Anith Sen" wrote:

> There are two T-SQL functions CAST and CONVERT which you use for type
> conversions. SQL Server Books Online has all the details and examples for
> using them.
> --
> Anith
>
>|||1. Datetime constants are represented as strings in the SQL language. String
s are surrounded by
single quotes in the SQL Language.
2. Since you have a nationalized datetime format (not recommended!), need to
use CONVERT and use the
3:rd format parameter (the style format). Else your code will fail with a no
n matching language
setting.
3. Since you compare against a string and the value in the table is a string
, why involve the
datetime datatype at all?
4. Why do you store datetimes as strings instead of datetimes?
5. You might want to check out: http://www.karaszi.com/SQLServer/in...ime.asp

Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:03322931-FD81-4F7A-940D-51EDD36B9C4C@.microsoft.com...[vbcol=seagreen]
> Hi thanks for the response, I tried the code below but get the error
> missing operator in query expression Cast(StartTime as DateTime)="3/03/200
5 "
> StartTime is a string column in a table that looks like "3/03/2005 10:11:4
5"
> Select * from tablename
> WHERE CAST(StartTime AS DateTime)= "3/03/2005 12:12:00"
> "Anith Sen" wrote:
>

cast from string to DateTime type

HI I am using a C++ builder routine that fills a datacontrol from the results
of a query. Just wondering if there is a way to cast from string type to
DateTime as the data is on a Microsoft SQL 2000 server, would like to perform
the cast in the query?
Thanks
Paul G
Software engineer.
There are two T-SQL functions CAST and CONVERT which you use for type
conversions. SQL Server Books Online has all the details and examples for
using them.
Anith
|||Hi thanks for the response, I tried the code below but get the error
missing operator in query expression Cast(StartTime as DateTime)="3/03/2005 "
StartTime is a string column in a table that looks like "3/03/2005 10:11:45"
Select * from tablename
WHERE CAST(StartTime AS DateTime)= "3/03/2005 12:12:00"
"Anith Sen" wrote:

> There are two T-SQL functions CAST and CONVERT which you use for type
> conversions. SQL Server Books Online has all the details and examples for
> using them.
> --
> Anith
>
>
|||1. Datetime constants are represented as strings in the SQL language. Strings are surrounded by
single quotes in the SQL Language.
2. Since you have a nationalized datetime format (not recommended!), need to use CONVERT and use the
3:rd format parameter (the style format). Else your code will fail with a non matching language
setting.
3. Since you compare against a string and the value in the table is a string, why involve the
datetime datatype at all?
4. Why do you store datetimes as strings instead of datetimes?
5. You might want to check out: http://www.karaszi.com/SQLServer/info_datetime.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:03322931-FD81-4F7A-940D-51EDD36B9C4C@.microsoft.com...[vbcol=seagreen]
> Hi thanks for the response, I tried the code below but get the error
> missing operator in query expression Cast(StartTime as DateTime)="3/03/2005 "
> StartTime is a string column in a table that looks like "3/03/2005 10:11:45"
> Select * from tablename
> WHERE CAST(StartTime AS DateTime)= "3/03/2005 12:12:00"
> "Anith Sen" wrote:

cast from string to DateTime type

HI I am using a C++ builder routine that fills a datacontrol from the results
of a query. Just wondering if there is a way to cast from string type to
DateTime as the data is on a Microsoft SQL 2000 server, would like to perform
the cast in the query?
Thanks
--
Paul G
Software engineer.There are two T-SQL functions CAST and CONVERT which you use for type
conversions. SQL Server Books Online has all the details and examples for
using them.
--
Anith|||Hi thanks for the response, I tried the code below but get the error
missing operator in query expression Cast(StartTime as DateTime)="3/03/2005 "
StartTime is a string column in a table that looks like "3/03/2005 10:11:45"
Select * from tablename
WHERE CAST(StartTime AS DateTime)= "3/03/2005 12:12:00"
"Anith Sen" wrote:
> There are two T-SQL functions CAST and CONVERT which you use for type
> conversions. SQL Server Books Online has all the details and examples for
> using them.
> --
> Anith
>
>|||1. Datetime constants are represented as strings in the SQL language. Strings are surrounded by
single quotes in the SQL Language.
2. Since you have a nationalized datetime format (not recommended!), need to use CONVERT and use the
3:rd format parameter (the style format). Else your code will fail with a non matching language
setting.
3. Since you compare against a string and the value in the table is a string, why involve the
datetime datatype at all?
4. Why do you store datetimes as strings instead of datetimes?
5. You might want to check out: http://www.karaszi.com/SQLServer/info_datetime.asp
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:03322931-FD81-4F7A-940D-51EDD36B9C4C@.microsoft.com...
> Hi thanks for the response, I tried the code below but get the error
> missing operator in query expression Cast(StartTime as DateTime)="3/03/2005 "
> StartTime is a string column in a table that looks like "3/03/2005 10:11:45"
> Select * from tablename
> WHERE CAST(StartTime AS DateTime)= "3/03/2005 12:12:00"
> "Anith Sen" wrote:
>> There are two T-SQL functions CAST and CONVERT which you use for type
>> conversions. SQL Server Books Online has all the details and examples for
>> using them.
>> --
>> Anith
>>

Friday, February 10, 2012

cast datetime to yyyymm format

How can I cast a datetime to a format of yyyymm?
firstdate and seconddate are both datetime fields and I want to use them in
the yyyymm format in my where clause below.
Declare @.curdate datetime
Set @.curdate = 2005/11
select firstdate, seconddate
from dates
where @.curdate between firstdate and seconddate
and firstdate < seconddate
Thanks!
MattI do not know any style argument to format it like that, but you can buid it
yourself in a function
DECLARE @.TestDate datetime
SET @.TestDate = GetDate()
SELECT CONVERT(varchar(4), @.TestDate, 120) + SUBSTRING(CONVERT(varchar(7),
@.TestDate, 120), 6, 2)
You can buid a function that takes a datetime argument and returns a varchar
.
HTH,
John Scragg
"Matt" wrote:

> How can I cast a datetime to a format of yyyymm?
> firstdate and seconddate are both datetime fields and I want to use them i
n
> the yyyymm format in my where clause below.
> Declare @.curdate datetime
> Set @.curdate = 2005/11
> select firstdate, seconddate
> from dates
> where @.curdate between firstdate and seconddate
> and firstdate < seconddate
> Thanks!
> Matt|||Try,
select convert(char(6), getdate(), 112)
go
AMB
"Matt" wrote:

> How can I cast a datetime to a format of yyyymm?
> firstdate and seconddate are both datetime fields and I want to use them i
n
> the yyyymm format in my where clause below.
> Declare @.curdate datetime
> Set @.curdate = 2005/11
> select firstdate, seconddate
> from dates
> where @.curdate between firstdate and seconddate
> and firstdate < seconddate
> Thanks!
> Matt|||2005/11 is not a date. A date requires year, month and day.
e.g., to find dates in Nov 2005,
set @.curdate='20051101'
select firstdate, seconddate
from dates
where firstdate<=@.curdate and seconddate>=dateadd(month,1,@.curdate)-1
and firstdate<seconddate
Matt wrote:

>How can I cast a datetime to a format of yyyymm?
>firstdate and seconddate are both datetime fields and I want to use them in
>the yyyymm format in my where clause below.
>Declare @.curdate datetime
>Set @.curdate = 2005/11
> select firstdate, seconddate
>from dates
>where @.curdate between firstdate and seconddate
> and firstdate < seconddate
>Thanks!
>Matt
>|||Thanks to you all for your help. It does appear that I get correct results
when I run the @.curdate as a char. When running as datetime the where claus
e
fails.
"Matt" wrote:

> How can I cast a datetime to a format of yyyymm?
> firstdate and seconddate are both datetime fields and I want to use them i
n
> the yyyymm format in my where clause below.
> Declare @.curdate datetime
> Set @.curdate = 2005/11
> select firstdate, seconddate
> from dates
> where @.curdate between firstdate and seconddate
> and firstdate < seconddate
> Thanks!
> Matt|||On Wed, 26 Oct 2005 12:41:18 -0700, Matt wrote:

>Thanks to you all for your help. It does appear that I get correct results
>when I run the @.curdate as a char. When running as datetime the where clau
se
>fails.
Hi Matt,
As Trey already wrote: 2005/11 is not a datetime. It is the division of
an integer by another integer. The result of 2005/11 is 182 (the decimal
portion is lost, because integer division is used). This result is then
converted to datetime, which will yield the 182nd day of the year 1900.
To check this, run
Declare @.curdate datetime
Set @.curdate = 2005/11
SELECT @.curdate
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Cast datetime to smalldatetime error

I have a table that I converted from MS Access and one of the colums I use t
o
store time values into has been converted to datetime and the year 1899 was
added to all existing records. I want to just display the time portion and
have tried the following code in the function I use to display the data:
CAST(ESR_CLOSE_TIME AS smalldatetime)
When I try to run the function I get an error saying the conversion resulted
in an overflow error. Any Ideas. Thanksyes - cast as datetime instead
the lowest smalldatetime value possible is Jan 1, 1900, so 1899 is out
of range.
AkAlan wrote:
> I have a table that I converted from MS Access and one of the colums I use
to
> store time values into has been converted to datetime and the year 1899 wa
s
> added to all existing records. I want to just display the time portion and
> have tried the following code in the function I use to display the data:
> CAST(ESR_CLOSE_TIME AS smalldatetime)
> When I try to run the function I get an error saying the conversion result
ed
> in an overflow error. Any Ideas. Thanks|||SELECT CONVERT(char(8), ESR_CLOSE_TIME , 108) --24hr time with seconds
SELECT RIGHT(CONVERT(char(19), ESR_CLOSE_TIME , 0),7) --with AM/ PM
The datetime datatype includes the date (year, month, day) and time with an
accuracy of 3/1000 of a second.
--
"AkAlan" wrote:

> I have a table that I converted from MS Access and one of the colums I use
to
> store time values into has been converted to datetime and the year 1899 wa
s
> added to all existing records. I want to just display the time portion and
> have tried the following code in the function I use to display the data:
> CAST(ESR_CLOSE_TIME AS smalldatetime)
> When I try to run the function I get an error saying the conversion result
ed
> in an overflow error. Any Ideas. Thanks

Cast DateTime To Date?

I have a datetime field in a database, but want to query on the date
portion only.
1. Can someone provide an example?
2. Any good online SQL resources specific to MSSQL dialect?
Thank you,
Warm Regards,
Lee
"Upon further investigation it appears that your software is missing
just one thing. It definitely needs more cow bell..."
1. Can someone provide an example?
Sure, SELECT CONVERT(VARCHAR(10),GETDATE(),112) --Look in the BOL for
more information about Convert.
2. Any good online SQL resources specific to MSSQL dialect?
Sure, look in the BOL for more information: http://www.aspfaq.com/2229
HTH, jens Suessmeyer.
|||Datetime to Date =>
This will work,
SELECT getdate()
SELECT CAST(FLOOR(CAST( getdate() AS float)) AS DATETIME)
For MSSQL dialect, look BOL
Thanks,
Sree
"Lee" wrote:

>
> I have a datetime field in a database, but want to query on the date
> portion only.
> 1. Can someone provide an example?
> 2. Any good online SQL resources specific to MSSQL dialect?
> Thank you,
> --
> Warm Regards,
> Lee
> "Upon further investigation it appears that your software is missing
> just one thing. It definitely needs more cow bell..."
>

Cast DateTime To Date?

I have a datetime field in a database, but want to query on the date
portion only.
1. Can someone provide an example?
2. Any good online SQL resources specific to MSSQL dialect?
Thank you,
--
Warm Regards,
Lee
"Upon further investigation it appears that your software is missing
just one thing. It definitely needs more cow bell..."1. Can someone provide an example?
Sure, SELECT CONVERT(VARCHAR(10),GETDATE(),112) --Look in the BOL for
more information about Convert.
2. Any good online SQL resources specific to MSSQL dialect?
Sure, look in the BOL for more information: http://www.aspfaq.com/2229
HTH, jens Suessmeyer.|||Datetime to Date =>
This will work,
SELECT getdate()
SELECT CAST(FLOOR(CAST( getdate() AS float)) AS DATETIME)
For MSSQL dialect, look BOL
Thanks,
Sree
"Lee" wrote:
>
> I have a datetime field in a database, but want to query on the date
> portion only.
> 1. Can someone provide an example?
> 2. Any good online SQL resources specific to MSSQL dialect?
> Thank you,
> --
> Warm Regards,
> Lee
> "Upon further investigation it appears that your software is missing
> just one thing. It definitely needs more cow bell..."
>

Cast DateTime To Date?

I have a datetime field in a database, but want to query on the date
portion only.
1. Can someone provide an example?
2. Any good online SQL resources specific to MSSQL dialect?
Thank you,
Warm Regards,
Lee
"Upon further investigation it appears that your software is missing
just one thing. It definitely needs more cow bell..."1. Can someone provide an example?
Sure, SELECT CONVERT(VARCHAR(10),GETDATE(),112) --Look in the BOL for
more information about Convert.
2. Any good online SQL resources specific to MSSQL dialect?
Sure, look in the BOL for more information: http://www.aspfaq.com/2229
HTH, jens Suessmeyer.|||Datetime to Date =>
This will work,
SELECT getdate()
SELECT CAST(FLOOR(CAST( getdate() AS float)) AS DATETIME)
For MSSQL dialect, look BOL
Thanks,
Sree
"Lee" wrote:

>
> I have a datetime field in a database, but want to query on the date
> portion only.
> 1. Can someone provide an example?
> 2. Any good online SQL resources specific to MSSQL dialect?
> Thank you,
> --
> Warm Regards,
> Lee
> "Upon further investigation it appears that your software is missing
> just one thing. It definitely needs more cow bell..."
>

Cast and Convert

I am trying to convert an INT to a Date value with is currently working with
the following query
SELECT CONVERT (DATETIME,(select CAST(INV_DT as char(8))from dates), 103)
However, the Date format is YYYY-MM-DD Time
Can I use Convert and Cast in the same statement. I really needs the dates
in DD/MM/YY format
Any help glady appreciated.
ThanksHow does the INT look like?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
news:eanimipDFHA.4052@.TK2MSFTNGP15.phx.gbl...
>I am trying to convert an INT to a Date value with is currently working wit
h the following query
> SELECT CONVERT (DATETIME,(select CAST(INV_DT as char(8))from dates), 103)
> However, the Date format is YYYY-MM-DD Time
> Can I use Convert and Cast in the same statement. I really needs the date
s in DD/MM/YY format
> Any help glady appreciated.
> Thanks
>|||19740121
So this should display 21/01/1974
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uuamrmpDFHA.228@.tk2msftngp13.phx.gbl...
> How does the INT look like?
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
> news:eanimipDFHA.4052@.TK2MSFTNGP15.phx.gbl...
>|||So the format is, as integer, YYYYMMDD. That is nice, as we can CAST it to C
HAR(8) and that format
is one of the formats which is language independent regarding datetime conve
rsions from string to
datetime. Try below:
SELECT CONVERT(char(10), CAST(CAST(INV_DT AS char(8)) AS datetime), 103)
I.e., cast int to string, then string to datetime, then datetime to string (
using a conversion
code).
The question is, of course, why you store dates as int instead of datetime..
. :-)
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
news:OC4m8qpDFHA.2824@.tk2msftngp13.phx.gbl...
> 19740121
> So this should display 21/01/1974
>
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote i
n message
> news:uuamrmpDFHA.228@.tk2msftngp13.phx.gbl...
>|||Thanks it has worked.. I am sure I tried this :-) Luckily I didn't design
this application. I don't know why they chose INT instead of a datetime
field. :-(
Cheers
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:epNDnLqDFHA.4072@.TK2MSFTNGP10.phx.gbl...
> So the format is, as integer, YYYYMMDD. That is nice, as we can CAST it to
> CHAR(8) and that format is one of the formats which is language
> independent regarding datetime conversions from string to datetime. Try
> below:
> SELECT CONVERT(char(10), CAST(CAST(INV_DT AS char(8)) AS datetime), 103)
> I.e., cast int to string, then string to datetime, then datetime to string
> (using a conversion code).
> The question is, of course, why you store dates as int instead of
> datetime... :-)
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
> news:OC4m8qpDFHA.2824@.tk2msftngp13.phx.gbl...
>

Cast and Convert

I am trying to convert an INT to a Date value with is currently working with
the following query
SELECT CONVERT (DATETIME,(select CAST(INV_DT as char(8))from dates), 103)
However, the Date format is YYYY-MM-DD Time
Can I use Convert and Cast in the same statement. I really needs the dates
in DD/MM/YY format
Any help glady appreciated.
Thanks
How does the INT look like?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
news:eanimipDFHA.4052@.TK2MSFTNGP15.phx.gbl...
>I am trying to convert an INT to a Date value with is currently working with the following query
> SELECT CONVERT (DATETIME,(select CAST(INV_DT as char(8))from dates), 103)
> However, the Date format is YYYY-MM-DD Time
> Can I use Convert and Cast in the same statement. I really needs the dates in DD/MM/YY format
> Any help glady appreciated.
> Thanks
>
|||19740121
So this should display 21/01/1974
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uuamrmpDFHA.228@.tk2msftngp13.phx.gbl...
> How does the INT look like?
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
> news:eanimipDFHA.4052@.TK2MSFTNGP15.phx.gbl...
>
|||So the format is, as integer, YYYYMMDD. That is nice, as we can CAST it to CHAR(8) and that format
is one of the formats which is language independent regarding datetime conversions from string to
datetime. Try below:
SELECT CONVERT(char(10), CAST(CAST(INV_DT AS char(8)) AS datetime), 103)
I.e., cast int to string, then string to datetime, then datetime to string (using a conversion
code).
The question is, of course, why you store dates as int instead of datetime... :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
news:OC4m8qpDFHA.2824@.tk2msftngp13.phx.gbl...
> 19740121
> So this should display 21/01/1974
>
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in message
> news:uuamrmpDFHA.228@.tk2msftngp13.phx.gbl...
>
|||Thanks it has worked.. I am sure I tried this :-) Luckily I didn't design
this application. I don't know why they chose INT instead of a datetime
field. :-(
Cheers
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:epNDnLqDFHA.4072@.TK2MSFTNGP10.phx.gbl...
> So the format is, as integer, YYYYMMDD. That is nice, as we can CAST it to
> CHAR(8) and that format is one of the formats which is language
> independent regarding datetime conversions from string to datetime. Try
> below:
> SELECT CONVERT(char(10), CAST(CAST(INV_DT AS char(8)) AS datetime), 103)
> I.e., cast int to string, then string to datetime, then datetime to string
> (using a conversion code).
> The question is, of course, why you store dates as int instead of
> datetime... :-)
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
> news:OC4m8qpDFHA.2824@.tk2msftngp13.phx.gbl...
>

Cast and Convert

I am trying to convert an INT to a Date value with is currently working with
the following query
SELECT CONVERT (DATETIME,(select CAST(INV_DT as char(8))from dates), 103)
However, the Date format is YYYY-MM-DD Time
Can I use Convert and Cast in the same statement. I really needs the dates
in DD/MM/YY format
Any help glady appreciated.
ThanksHow does the INT look like?
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
news:eanimipDFHA.4052@.TK2MSFTNGP15.phx.gbl...
>I am trying to convert an INT to a Date value with is currently working with the following query
> SELECT CONVERT (DATETIME,(select CAST(INV_DT as char(8))from dates), 103)
> However, the Date format is YYYY-MM-DD Time
> Can I use Convert and Cast in the same statement. I really needs the dates in DD/MM/YY format
> Any help glady appreciated.
> Thanks
>|||19740121
So this should display 21/01/1974
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uuamrmpDFHA.228@.tk2msftngp13.phx.gbl...
> How does the INT look like?
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
> news:eanimipDFHA.4052@.TK2MSFTNGP15.phx.gbl...
>>I am trying to convert an INT to a Date value with is currently working
>>with the following query
>> SELECT CONVERT (DATETIME,(select CAST(INV_DT as char(8))from dates), 103)
>> However, the Date format is YYYY-MM-DD Time
>> Can I use Convert and Cast in the same statement. I really needs the
>> dates in DD/MM/YY format
>> Any help glady appreciated.
>> Thanks
>>
>|||So the format is, as integer, YYYYMMDD. That is nice, as we can CAST it to CHAR(8) and that format
is one of the formats which is language independent regarding datetime conversions from string to
datetime. Try below:
SELECT CONVERT(char(10), CAST(CAST(INV_DT AS char(8)) AS datetime), 103)
I.e., cast int to string, then string to datetime, then datetime to string (using a conversion
code).
The question is, of course, why you store dates as int instead of datetime... :-)
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
news:OC4m8qpDFHA.2824@.tk2msftngp13.phx.gbl...
> 19740121
> So this should display 21/01/1974
>
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in message
> news:uuamrmpDFHA.228@.tk2msftngp13.phx.gbl...
>> How does the INT look like?
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://www.solidqualitylearning.com/
>> http://www.sqlug.se/
>>
>> "Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
>> news:eanimipDFHA.4052@.TK2MSFTNGP15.phx.gbl...
>>I am trying to convert an INT to a Date value with is currently working with the following query
>> SELECT CONVERT (DATETIME,(select CAST(INV_DT as char(8))from dates), 103)
>> However, the Date format is YYYY-MM-DD Time
>> Can I use Convert and Cast in the same statement. I really needs the dates in DD/MM/YY format
>> Any help glady appreciated.
>> Thanks
>>
>>
>|||Thanks it has worked.. I am sure I tried this :-) Luckily I didn't design
this application. I don't know why they chose INT instead of a datetime
field. :-(
Cheers
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:epNDnLqDFHA.4072@.TK2MSFTNGP10.phx.gbl...
> So the format is, as integer, YYYYMMDD. That is nice, as we can CAST it to
> CHAR(8) and that format is one of the formats which is language
> independent regarding datetime conversions from string to datetime. Try
> below:
> SELECT CONVERT(char(10), CAST(CAST(INV_DT AS char(8)) AS datetime), 103)
> I.e., cast int to string, then string to datetime, then datetime to string
> (using a conversion code).
> The question is, of course, why you store dates as int instead of
> datetime... :-)
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
> news:OC4m8qpDFHA.2824@.tk2msftngp13.phx.gbl...
>> 19740121
>> So this should display 21/01/1974
>>
>> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote
>> in message news:uuamrmpDFHA.228@.tk2msftngp13.phx.gbl...
>> How does the INT look like?
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://www.solidqualitylearning.com/
>> http://www.sqlug.se/
>>
>> "Sarah Kingswell" <skingswell@.xonitek.co.uk> wrote in message
>> news:eanimipDFHA.4052@.TK2MSFTNGP15.phx.gbl...
>>I am trying to convert an INT to a Date value with is currently working
>>with the following query
>> SELECT CONVERT (DATETIME,(select CAST(INV_DT as char(8))from dates),
>> 103)
>> However, the Date format is YYYY-MM-DD Time
>> Can I use Convert and Cast in the same statement. I really needs the
>> dates in DD/MM/YY format
>> Any help glady appreciated.
>> Thanks
>>
>>
>>
>