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

IS THERE A FUNCTION THAT RETURNS CURRENT YEAR MONTH AND QUARTER in SQL 1

Status
Not open for further replies.

TNN

Programmer
Sep 13, 2000
417
US
In VB6.0 I can use the DatePart function to return the current year, month and quarter per the system current date.
See below code:

'Determine current Month, Quarter and Year.
Month = DatePart("m", Date)
Qtr = DatePart("q", Date)
Year = DatePart("yyyy", Date)
'Check to see if this is a leap year. Boolean value used in Select Case below.
ThisIsALeapYear = IsDate("2/29/" & Year)

Is there anything similar in SQL???

Thank You, TNNTom

TOM
 
It all works the same in VBA.

From the debug window:
MyMonth = DatePart("m", Date)
MyQtr = DatePart("q", Date)
MyYear = DatePart("yyyy", Date)
? mymonth
5
? MyQtr
2
? MyYear
2002
 
MS Sql Server also has datepart. Look it up on the on line help
 
Thanks pweegar.
The below query is about where I want to be but:

SELECT SUM(ADVEIC + FIT_TAX + FICA_TAX + HI_TAX + ERFICA_TAX + ERHI_TAX) AS QTRTTL
FROM EMPEARNPERWAGE
WHERE DATEPART("q",DATEPAID)=2 AND DATEPART("yyyy",DATEPAID)=2002

How can I replace the =2 and =2002 with a function that pulls the current quarter and year based on the system date??
TNNTom

TOM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top