Showing posts with label tsql. Show all posts
Showing posts with label tsql. Show all posts

Sunday, February 19, 2012

date convert question

In TSQL, How could I convert the following string date time into string date
format of 'mm/dd/yyyy'
Aug 23 2005 9:27AM
TIA...I just came up with this one
select convert(varchar(20),cast('Aug 23 2005 9:27AM' as datetime),101)
Any other ideas'
"sqlster" wrote:

> In TSQL, How could I convert the following string date time into string da
te
> format of 'mm/dd/yyyy'
> Aug 23 2005 9:27AM
> TIA...|||sqlster wrote:
> In TSQL, How could I convert the following string date time into
> string date format of 'mm/dd/yyyy'
> Aug 23 2005 9:27AM
> TIA...
SQL Server dates do not have formatting attached to them. When you want
to convery a string representation of a date to a SQL Server DATETIME
data type, you should always use a portable format like YYYYMMDD.
If you need the output of the query to return in a USA date format, you
can use the CONVERT function with the correct style. Style 101 should
give you what you want. Although, I would encourage you to format dates
on the client whenever possible.
Select CONVERT(CHAR(10), CAST('20050823' as DATETIME), 101) -- with
century
Select CONVERT(CHAR(10), CAST('20050823' as DATETIME), 1) -- without
century
David Gugick
Quest Software
www.imceda.com
www.quest.com|||sqlster wrote:
> In TSQL, How could I convert the following string date time into
> string date format of 'mm/dd/yyyy'
> Aug 23 2005 9:27AM
> TIA...
If you need to use a time as well, use the following portable format:
yyyy-mm-ddThh:mm:ss.mmm (no spaces)
David Gugick
Quest Software
www.imceda.com
www.quest.com

DATE CONVERSION

How to convert DATE from one format to another.
datatype: datetime
original format: 2006-09-25 10:48:19.000
I need to convert to 2006-09-25
any TSQL function? I want to do this in a single SQL query. The above
date value can be NULL as well. If it is null, It should no do
anything.
Thanks.
Hi,
You could use CONVERT function.
select convert(char(10),getdate(),20)
Thanks
hari
SQL Server MVP
<krallabandi@.gmail.com> wrote in message
news:1158939304.788022.14330@.i42g2000cwa.googlegro ups.com...
> How to convert DATE from one format to another.
> datatype: datetime
> original format: 2006-09-25 10:48:19.000
> I need to convert to 2006-09-25
> any TSQL function? I want to do this in a single SQL query. The above
> date value can be NULL as well. If it is null, It should no do
> anything.
> Thanks.
>

Friday, February 17, 2012

DATE CONVERSION

How to convert DATE from one format to another.
datatype: datetime
original format: 2006-09-25 10:48:19.000
I need to convert to 2006-09-25
any TSQL function? I want to do this in a single SQL query. The above
date value can be NULL as well. If it is null, It should no do
anything.
Thanks.Hi,
You could use CONVERT function.
select convert(char(10),getdate(),20)
Thanks
hari
SQL Server MVP
<krallabandi@.gmail.com> wrote in message
news:1158939304.788022.14330@.i42g2000cwa.googlegroups.com...
> How to convert DATE from one format to another.
> datatype: datetime
> original format: 2006-09-25 10:48:19.000
> I need to convert to 2006-09-25
> any TSQL function? I want to do this in a single SQL query. The above
> date value can be NULL as well. If it is null, It should no do
> anything.
> Thanks.
>

DATE CONVERSION

How to convert DATE from one format to another.
datatype: datetime
original format: 2006-09-25 10:48:19.000
I need to convert to 2006-09-25
any TSQL function? I want to do this in a single SQL query. The above
date value can be NULL as well. If it is null, It should no do
anything.
Thanks.Hi,
You could use CONVERT function.
select convert(char(10),getdate(),20)
Thanks
hari
SQL Server MVP
<krallabandi@.gmail.com> wrote in message
news:1158939304.788022.14330@.i42g2000cwa.googlegroups.com...
> How to convert DATE from one format to another.
> datatype: datetime
> original format: 2006-09-25 10:48:19.000
> I need to convert to 2006-09-25
> any TSQL function? I want to do this in a single SQL query. The above
> date value can be NULL as well. If it is null, It should no do
> anything.
> Thanks.
>