Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting month only and year only

Status
Not open for further replies.

Leakyradiator

Technical User
Jul 12, 2002
35
0
0
US
I want to insert a month value into a column entitled "month" and the year value into another column entitled "year"...

Can this be done with date/time data types in these columns? And how would you do it?

Everything I've been able to read on how to do it, uses complete mm/dd/yy and I only want to use part of the date. The datepart function seems to only extract the date part from an existing date.

Thanks in Advance
 
Hi,
(1)DatePart(mm,GetDate()) for month
(2)DatePart(yyyy,GetDate()) for year in four digits
(3)DatePArt(yy,GetDate()) for year with last two digits

Use any datetime type of coulmn in place of GetDate() if that's what you want to do.


Hope this helps.

Sreenivas
avnsr@hotmail.com
-----------------
 
In answer to your question, datetime data types always store the whole date and time. you can use DatePart as above to display only the parts you want or you can use columns of a different type to store just the information you want. Then of course you would have to concatente the fields together and convert to datetime if you want to see the whole date.
 
If you want to insert Month and Year into columns, set the columns as INT data type unless you want the month to be 'jan', 'feb', etc. In this case, use a char or varchar type.

I recommend that you DO NOT use Month and Year as column names. These are reserved words and Function names in SQL Server. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top