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...
>
Showing posts with label withthe. Show all posts
Showing posts with label withthe. Show all posts
Friday, February 10, 2012
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...
>
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...
>
Subscribe to:
Posts (Atom)