473,810 Members | 3,102 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert month No into its number ..(Ex. 1= Jan,2= Feb...)

1 New Member
Hi All,

How can we conevrt the Month no into its equivalent name..(Ex. 1= Jan,2= Feb...) & IF you can tell me how to contatenate the Month & Year in one column.
Here is the query which I am writing.

SELECT
Datepart(Year, UserData.tp_Cre ated),
MONTH(UserData. tp_Created),
FROM TABEL1

I want to have Month & year info into one column. data should be like Jan 2007, feb 2006 like this.
Pls suggest,

Thanks in Advance!!
Aug 2 '07 #1
5 10058
bwestover
39 New Member
Try this:

Expand|Select|Wrap|Line Numbers
  1. Select Case Month(UserData.tp_Created)
  2. When 1 Then 'Jan'
  3. When 2 Then 'Feb'
  4. When 3 Then 'Mar' (etc.....)
  5. End + ' ' + convert(char(4),year(UserData.tp_Created))
  6. From Table1
Aug 2 '07 #2
odyoda
2 New Member
Or, for less code:

LEFT(CONVERT( CHAR(19),UserDa ta.tp_Created,1 00),3)+ ' ' + RIGHT(YEAR(User Data.tp_Created ),4)

Just wrote this one myself today for our web dev.
Aug 6 '07 #3
ck9663
2,878 Recognized Expert Specialist
Try this:

Expand|Select|Wrap|Line Numbers
  1. Select Case Month(UserData.tp_Created)
  2. When 1 Then 'Jan'
  3. When 2 Then 'Feb'
  4. When 3 Then 'Mar' (etc.....)
  5. End + ' ' + convert(char(4),year(UserData.tp_Created))
  6. From Table1
try this:

select substring(conve rt(char(8), UserData.tp_Cre ated,1),1,2)
from table1
Aug 7 '07 #4
odyoda
2 New Member
try this:

select substring(conve rt(char(8), UserData.tp_Cre ated,1),1,2)
from table1
All that does is return the "08". He is trying to then format that integer into the 3 character standardized month code followed by the 2-digit year.
Aug 7 '07 #5
bwestover
39 New Member
Yeah, ODYODA's got it right. And way cleaner than my way :)

Welcome to the Forums!!
Aug 10 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

19
7296
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below. Specifically, I have a problem with this portion in the WHERE clause: DATEADD(Day,tblMyEventTableName.ReminderDays, @DateNow) Between CONVERT(smalldatetime,str(DATEPART(Month, @DateNow)+1) + '/' + str(DATEPART(Day, tblMyEventTableName.TaskDateTime)) + '/'...
4
5395
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
1
6483
by: Matt | last post by:
I would like to convert a couple informix stored procedures to SQL Server stored procedures. I have no idea how to accomplish this. Here is an example of one of the procedures I need to convert. drop function mnaf_calc_calendar_quarter; CREATE FUNCTION mnaf_calc_calendar_quarter(pEndDate Date) --***************************************************************************** -- Name: mnaf_calc_calendar_quarter -- Description/Notes:
5
4938
by: PCV | last post by:
Hi All, I want to create a custom auto number in a form that looks like "CRA05001" where "CR" are fixed characters, then "A" should be for January as "B" for February and so on...(this part will change depending on the month, "05001" is the year "05" and "001" a sequential increment. I Know how to get "CR?05001" but I'm stuck on trying to convert the month number to the alpha characters. Any suggestions? Thanks in advance. This is a...
7
13884
by: Erik Cato | last post by:
Hi group! Anyone know a way to convert the __DATE__ predefined macro into a unsigned int representing the current date? It should be possible to make out what date it was from the beginning. My idéa was this format: ((Year - 2000)*12 + (month - 1))*31 + day So 12 Dec 2003 would result in: ((2003 - 2000)*12 + (12 - 1))*31 + 12 = 1469 <OT> What im trying to accomplish is to display a number representing
10
162686
by: bonnie.tangyn | last post by:
Dear all In my ASP page, user can enter date in dd/mm/yyyy format. How can I use Javascript to convert dd/mm/yyyy to yyyy-mm-dd hh:mm:ss. Please give me some advices. Cheers Bon
3
14314
by: LimaCharlie | last post by:
Good Day to Everyone, Need help! I have this SQL table w/ fieldname "PayPeriod". Sample value of PayPeriod are SEP06-1, SEP06-2, OCT06-1, OCT06-2... Wherein the first 3 chars is the month, 06 is the year, 1 or 2 is the cutoff where 1 means the 2nd half of the previous month and 2 is the first half of the current month. Now my questions are: 1.) How can I select these values sorted according to date. Since this is a character data...
4
39351
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that will convert each of the records of these service dates to the first date of that month, with results showing: 7/1/2006, 7/1/2006, 7/1/2006. How would you place an expression on a query that will convert any given date to the first day of the month...
2
26574
by: CindySue | last post by:
Hello--I've got a query that uses DatePart("m",) to select records for a particular month, and then a report based on that query. I'd like to be able to create a field in the report that says what month they are for. I can get the month number by using =DatePart("m",) in a text box, but I can't find a way to convert it to the month name. I've experimented with a couple of things I found in the forum, but I'm not talented enough to get them to...
12
23225
by: Be Borth | last post by:
I saw previous solutions to convert a month number (1) to a month name (January). I have a database with 200+ dates. In a query, I use the "Part" function DatePart("m",), to extract the month (number) and all month extracts worked correctly (they returned the correct numerical month). However, when I attempted adding a field in the query to format that extracted month to a month name, it only returned January and December - for all 200+...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10124
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.