Solved

How to convert date in dd Mon yyyy?

Posted on 2000-03-30
14
987 Views
Last Modified: 2008-03-17
I want to convert date to format dd Mon yyyy such as 14 April 2000. How? The method as simple as possible
0
Comment
Question by:cswkk98
14 Comments
 
LVL 1

Expert Comment

by:vujos
ID: 2669066
Hi,

You can use

<% FullDate = Month(date) & "/" & Day(date) & "/" & Year(date)
' FullDate is the combination of the exact Month, Day and Year.
' It will be used to assign the value of the hidden field. %>

Complete article at http://support.microsoft.com/support/kb/articles/Q183/0/49.ASP

Or read http://support.microsoft.com/support/kb/articles/Q222/1/78.ASP that will provide you with complete explanation.

Hope this helps.
0
 
LVL 2

Expert Comment

by:formula
ID: 2669129
This converts system date to what you want:

select convert(varchar(12), getdate(),106)

Just replace "getdate()"  with your date variable.   If you have any questions, please let me know.
0
 
LVL 10

Expert Comment

by:paasky
ID: 2669998
formula, great suggestion !

just my 2 cents: change varchar(12) to varchar(16) to prevent date cutting from the end.

Regards,
Paasky

0
 
LVL 2

Expert Comment

by:formula
ID: 2670186
Paasky,

If you want to display time, I agree.  But the "106" style doesn't include time, so 12 characters is long enough.
0
 
LVL 10

Expert Comment

by:paasky
ID: 2670242
formula,

I have to say I'm not very familiar with SQL Server so I tested your suggestion and got the following resultsets (this is Finnish):

30 maalis 20  (same as '30 March 2000')
27 tammi 200  (same as '27 January 2000')

so it seems that last one/two zeroes are missing from the year. What's causing this?

Paasky
0
 
LVL 2

Expert Comment

by:formula
ID: 2670570
Language is the difference. When I do this, I get the following:

30 Mar 2000
27 Jan 2000

In the English character set for SQLServer, the months are always three characters abbreviated for a "106" style.  Looks like in Finnish, it's different.  So I'll revise my statement to "In English, 12 characters is sufficient".  I did not realize you were using a different language.  I suggest making the character field as large as it needs to be for your language character set.

0
 
LVL 10

Expert Comment

by:paasky
ID: 2670647
formula, thank you for resolving the difference. How do you get full month name in English regional settings, for eg. '30 March 2000' or '1 December 2000'?

Paasky
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 10

Expert Comment

by:paasky
ID: 2670650
106 seems to view short month name...
0
 
LVL 2

Expert Comment

by:formula
ID: 2670806
Here are all the style possibilities in English for dates:

Style      Result

100   Mar 30 2000  4:01PM      
101   03/30/2000                
102   2000.03.30                
103   30/03/2000                
104   30.03.2000                
105   30-03-2000                
106   30 Mar 2000              
107   Mar 30, 2000
108   Time Only 16:01:40        
109   Mar 30 2000  4:01:40:090PM
110   03-30-2000                
111   2000/03/30                
112   20000330                  
113   30 Mar 2000 16:01:40:090  
114   Time Only 16:01:40:090    


As you can see, months are always abbreviated. No way to get full name, except to program it using datepart functions.
0
 
LVL 10

Expert Comment

by:paasky
ID: 2670862
formula, that was good information.

Would you show how to program it - I think the Customer wants the full month name: "... format dd Mon yyyy such as 14 April 2000 ..."

Paasky
0
 
LVL 2

Expert Comment

by:formula
ID: 2670916
Here's an example.  Copy this code in SQL window and run it to see result:

/* Function for creating specific date format output */

declare @day varchar(2),
        @month varchar(8),
        @year char(4),
        @initialdate datetime,
        @convertdate varchar(16)

select @initialdate=getdate()

select @day=convert(char(2),datepart(dd,@initialdate))
if (select datepart(mm,@initialdate))=1 select @month='January'
if (select datepart(mm,@initialdate))=2 select @month='February'
if (select datepart(mm,@initialdate))=3 select @month='March'
if (select datepart(mm,@initialdate))=4 select @month='April'
if (select datepart(mm,@initialdate))=5 select @month='May'
if (select datepart(mm,@initialdate))=6 select @month='June'
if (select datepart(mm,@initialdate))=7 select @month='July'
if (select datepart(mm,@initialdate))=8 select @month='August'
if (select datepart(mm,@initialdate))=9 select @month='September'
if (select datepart(mm,@initialdate))=10 select @month='October'
if (select datepart(mm,@initialdate))=11 select @month='November'
if (select datepart(mm,@initialdate))=12 select @month='December'
select @year=convert(char(4),datepart(yy,getdate()))

select @convertdate=@day+ " " + @month + " " + @year

select @convertdate  -- This statement just prints result to screen

I'm offline for rest of the day.  I'll be be back tomorrow if you have any questions.






0
 
LVL 4

Accepted Solution

by:
Gustavo Perez Buenrostro earned 200 total points
ID: 2671120
Hi, everybody.
This query lets you convert a datetime datatype value to cswkk98's date format (dd Month yyyy):

set language us_english

select convert(varchar,datepart(d,getdate()))
      +space(1)
      +datename(m,getdate())
      +space(1)
      +convert(varchar,datepart(yy,getdate()))



Here is the result:

--------------------------------------------------------------------------------------------
30 March 2000



This is for passky:

set language Suomi

select convert(varchar,datepart(d,getdate()))
      +space(1)
      +datename(m,getdate())
      +space(1)
      +convert(varchar,datepart(yy,getdate()))



Here is the result:

--------------------------------------------------------------------------------------------
30 maaliskuuta 2000
0
 
LVL 2

Expert Comment

by:formula
ID: 2672893
gpbuenrostro,

You answer works for SQL 7.0 just fine, but not SQL 6.5.  I don't know which flavor of SQL 'passky' or 'cswkk98' have, so I gave a example that works for both.  But thanks for the 7.0 example, I learned some new features.
0
 
LVL 10

Expert Comment

by:paasky
ID: 2673161
gpbuenrostro, we upgraded to version 7.0 just some months ago, so your solution was working with me. Thanks for language information.

formula, your code is also great.

Paasky


0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now