Unix Technical Forum

what is equivalent of format(date) function of MS Access in MS Sql Server 2000

This is a discussion on what is equivalent of format(date) function of MS Access in MS Sql Server 2000 within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi All, I am facing a problem with a sql what i used in MS Access but its not ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:12 PM
Leader
 
Posts: n/a
Default what is equivalent of format(date) function of MS Access in MS Sql Server 2000

Hi All,
I am facing a problem with a sql what i used in MS Access but its not
returning the same result in MS Sql Server 2000. Here i am giving the
sql:

SELECT TOP 3 format( MY_DATE, "dddd mm, yyyy" ) FROM MY_TAB WHERE
MY_ID=1

The above sql in ACCESS return me the date in below format in one
column:

Friday 09, 2003

But in Sql server 2000 i am not getting the same format eventhough i
am using convert function, date part function etc.

Please if you find the solution would be helpful for me..

Thanks
Hoque
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:12 PM
John Bell
 
Posts: n/a
Default Re: what is equivalent of format(date) function of MS Access in MS Sql Server 2000

Hi

If you field is a datetime, you can use the CONVERT function to convert it
to a formatted string. See books online for more information.

John

"Leader" <sohelcsc@yahoo.com> wrote in message
news:b1a93c73.0307220003.7f068543@posting.google.c om...
> Hi All,
> I am facing a problem with a sql what i used in MS Access but its not
> returning the same result in MS Sql Server 2000. Here i am giving the
> sql:
>
> SELECT TOP 3 format( MY_DATE, "dddd mm, yyyy" ) FROM MY_TAB WHERE
> MY_ID=1
>
> The above sql in ACCESS return me the date in below format in one
> column:
>
> Friday 09, 2003
>
> But in Sql server 2000 i am not getting the same format eventhough i
> am using convert function, date part function etc.
>
> Please if you find the solution would be helpful for me..
>
> Thanks
> Hoque



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 06:13 PM
Erland Sommarskog
 
Posts: n/a
Default Re: what is equivalent of format(date) function of MS Access in MS Sql Server 2000

Leader (sohelcsc@yahoo.com) writes:
> I am facing a problem with a sql what i used in MS Access but its not
> returning the same result in MS Sql Server 2000. Here i am giving the
> sql:
>
> SELECT TOP 3 format( MY_DATE, "dddd mm, yyyy" ) FROM MY_TAB WHERE
> MY_ID=1
>
> The above sql in ACCESS return me the date in below format in one
> column:
>
> Friday 09, 2003
>
> But in Sql server 2000 i am not getting the same format eventhough i
> am using convert function, date part function etc.


This gives you what you want:

select datename(dw, getdate()) + ' ' + datename(dd, getdate()) + ', ' +
datename(yyyy, getdate())

Well almost. You don't get any leading zero for a one-digit date.

--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 06:13 PM
Random
 
Posts: n/a
Default Re: what is equivalent of format(date) function of MS Access in MS Sql Server 2000

I am not certain about the type, but something like
CONVERT(varchar,MY_DATE,112) should work....

The 112 part may be incorrect, look up CONVERT in the Query Analyzer
help file... It shows the format numbers.



On Tue, 22 Jul 2003 21:42:55 +0000 (UTC), Erland Sommarskog
<sommar@algonet.se> wrote:

>Leader (sohelcsc@yahoo.com) writes:
>> I am facing a problem with a sql what i used in MS Access but its not
>> returning the same result in MS Sql Server 2000. Here i am giving the
>> sql:
>>
>> SELECT TOP 3 format( MY_DATE, "dddd mm, yyyy" ) FROM MY_TAB WHERE
>> MY_ID=1
>>
>> The above sql in ACCESS return me the date in below format in one
>> column:
>>
>> Friday 09, 2003
>>
>> But in Sql server 2000 i am not getting the same format eventhough i
>> am using convert function, date part function etc.

>
>This gives you what you want:
>
> select datename(dw, getdate()) + ' ' + datename(dd, getdate()) + ', ' +
> datename(yyyy, getdate())
>
>Well almost. You don't get any leading zero for a one-digit date.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:41 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com