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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Only the month(char) and year from the date

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I tried to use Convert function.But this doenot help to get only the month and year in a date.
I could do it in Access using Format function.But how do i do it in Sql Server?

Thanks
Uma.
 
I don't know jack about SQL server (and this is an Access forum). The DatePart function will give you what you want in Access context. Here's the pertinent Access help selection (you could concatenate the function results to get both month and year):

Extract part of existing date values using a calculated field
In query Design view, create a query. Add the tables whose records you want to use.


Use the DatePart function in an expression in an empty cell in the Field row in the query design grid.
The syntax for this function is:

DatePart(datepart,date)

The datepart argument is the abbreviation for the part of the date you want returned. Examples are "yyyy" for a four-digit year and "q" for a calendar quarter. The date argument is either a field name with the Date/Time data type or a literal date such as "7-Nov-93".

The following table lists examples of expressions that apply the DatePart function to the OrderDate field from the Orders table. If the value in
OrderDate is
This expression
Returns
3-Jun-93 DatePart("m",[OrderDate]) 6 (month of year)
28-Mar-92 DatePart("yyyy",[OrderDate]) 1992 (four-digit number of year)


Add any other fields you want to include in the query to the query design grid.

 
Q: There a PRODUCT table with a primary PRODUCT_ID key. There is a TRANSACTION table that records PRODUCT purchases. The TRANSACTION table contains duplicate PRODUCT_ID fields and and a TIMESTAMP date field that records the date of the transaction. How can I construct a query/expression to count how many of each PRODUCT_IDs were "transacted" over a 24 hour period?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top