Sunday, February 19, 2012

DateFormat

Hi all
Whenever I use the cOnvert function to convert the date
format to other format I always get the same format of
date.
eg:
For the date '2003-12-02 09:00:00.000'
I use select convert(datetime,ShiftStartTime,126)
still getting the same output as
'2003-12-02 09:00:00.000'
but supposed to be in the format dd/mm/yy hh:mi:ss:mmmAM
as per BOL.
Please carify.
Thanks in advance
Anand.Internally, SQL stores the date with all the information it needs. You are
converting a DateTime to DateTime, if you want to display it in a certain
format, you have to use:
convert(NCHAR(23),ShiftStartTime,126)
This converts it to a string that is formatted how you want it.
--
--
Mike Epprecht, Microsoft SQL Server MVP
Epprecht Consulting (PTY) LTD
Johannesburg, South Africa
Mobile: +27-82-552-0268
IM: mike@.NOSPAMepprecht.net
Specialist SQL Server Solutions and Consulting
"Anand" <gurusanand@.yahoo.com> wrote in message
news:01f501c3d685$fa191c90$a001280a@.phx.gbl...
> Hi all
> Whenever I use the cOnvert function to convert the date
> format to other format I always get the same format of
> date.
> eg:
> For the date '2003-12-02 09:00:00.000'
> I use select convert(datetime,ShiftStartTime,126)
> still getting the same output as
> '2003-12-02 09:00:00.000'
> but supposed to be in the format dd/mm/yy hh:mi:ss:mmmAM
> as per BOL.
> Please carify.
> Thanks in advance
> Anand.
>|||The problem is that you needed to convert the date to a char or varchar, not
datetime...
--
Wayne Snyder, MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
www.computeredservices.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Anand" <gurusanand@.yahoo.com> wrote in message
news:01f501c3d685$fa191c90$a001280a@.phx.gbl...
> Hi all
> Whenever I use the cOnvert function to convert the date
> format to other format I always get the same format of
> date.
> eg:
> For the date '2003-12-02 09:00:00.000'
> I use select convert(datetime,ShiftStartTime,126)
> still getting the same output as
> '2003-12-02 09:00:00.000'
> but supposed to be in the format dd/mm/yy hh:mi:ss:mmmAM
> as per BOL.
> Please carify.
> Thanks in advance
> Anand.
>

No comments:

Post a Comment