Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Date Format

 
   Database Help (Home) -> Programming RSS
Next:  Using the result of one query as search criteria ..  
Author Message
balajikkrishnan via SQLMo

External


Since: Mar 18, 2008
Posts: 22



(Msg. 1) Posted: Tue Apr 29, 2008 2:05 am
Post subject: Date Format
Archived from groups: microsoft>public>sqlserver>programming (more info?)

Hi All,

Can any one tell me how to format the date time in tsql in this format

mm/dd/yyyy hh:mm am/pm (1/22/2009 6:00am)

Thanks
Balaji

--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/200804/1

 >> Stay informed about: Date Format 
Back to top
Login to vote
"Roy Harvey

External


Since: Jan 12, 2008
Posts: 593



(Msg. 2) Posted: Tue Apr 29, 2008 2:05 am
Post subject: Re: Date Format [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

This is close:

declare @d datetime
set @d = '22 Jan 2009 6:00'

SELECT convert(char(10),@d,101) +
RIGHT(convert(char(19),@d,100),Cool

This returns 01/22/2009 6:00AM. It matches what you requested, with
the exception of the space before the am/pm. It differs from your
sample result in that it has the leading zero on the month and two
spaces between the year and hour when the hour is not two digits.

Roy Harvey
Beacon Falls, CT

On Tue, 29 Apr 2008 02:05:44 GMT, "balajikkrishnan via SQLMonster.com"
wrote:

>Hi All,
>
>Can any one tell me how to format the date time in tsql in this format
>
>mm/dd/yyyy hh:mm am/pm (1/22/2009 6:00am)
>
>Thanks
>Balaji

 >> Stay informed about: Date Format 
Back to top
Login to vote
Aaron Bertrand [SQL Serve

External


Since: Jan 10, 2008
Posts: 2166



(Msg. 3) Posted: Tue Apr 29, 2008 2:05 am
Post subject: Re: Date Format [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

You can fix those things easy, but it's ugly...

REPLACE(REPLACE(REPLACE(<expression>, ' ', ' '), 'AM', ' AM'), 'PM', ' PM')

Specs weren't clear anyway, "hh:mm am/pm" does not match "6:00am" ... if
taken literally it should be "06:00 am"...




"Roy Harvey (SQL Server MVP)" wrote in message

> This is close:
>
> declare @d datetime
> set @d = '22 Jan 2009 6:00'
>
> SELECT convert(char(10),@d,101) +
> RIGHT(convert(char(19),@d,100),Cool
>
> This returns 01/22/2009 6:00AM. It matches what you requested, with
> the exception of the space before the am/pm. It differs from your
> sample result in that it has the leading zero on the month and two
> spaces between the year and hour when the hour is not two digits.
>
> Roy Harvey
> Beacon Falls, CT
>
> On Tue, 29 Apr 2008 02:05:44 GMT, "balajikkrishnan via SQLMonster.com"
> wrote:
>
>>Hi All,
>>
>>Can any one tell me how to format the date time in tsql in this format
>>
>>mm/dd/yyyy hh:mm am/pm (1/22/2009 6:00am)
>>
>>Thanks
>>Balaji
 >> Stay informed about: Date Format 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Date Format. - Doing this in SQL 2005. SELECT OrderDate FROM MoxyOrders And my OrderDate has a DataType of DateTime. When I run this, I get the date and time. Like 8/5/2008 11:50:20 AM 8/6/2008 2:15:30 PM 8/6/2008 3:30:45 PM etc. When I run this statemen...

Format Date predefined - Hi, is there any predefined format of date like this? 2007-Dec-01 I know that I can do it, but I need to know if there is any predefined. Thank you.

Is a UDT the best way to force the format of a date? - I have a smalldatetime called MyDate in a table. Anytime a user accesses MyDate with a select statement. I would like to have MyDate returned in the format mm/dd/yyyy. I would like the user to not have to explicitly put CONVERT(CHAR(10),MyDate,101) in...

Convert DateTime to Date format - How do I convert a datetime field to date only? I would like to convert: 2008-10-31 12:23:30 to 31/10/2008

DATEPART and DATEDIFF using VARCHAR(24) Date Format - My counterdatetime field format is varchar(24) listed below. This format cannot be changed because it's output from perfmon. How can I change the sql query to recognize DATEPART and DATEDIFF with my counterdatetime field in varchar(24) format. Please...
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]