Ita Brennan -- Chief Financial Officer
Thanks, Jayshree, and good afternoon. This analysis of our Q2 results and our guidance for Q3 18 is based on non-GAAP and excludes all non-cash stock-based compensation impacts and impairment of our private company equity investments and legal costs associated with the ongoing lawsuits. A full reconciliation of our selected GAAP to non-GAAP results is provided in our earnings release.
Total revenues in Q2 were $519.8 million, up 28% year over year and above our guidance of $500 million to $514 million. We were pleased with overall demand in the quarter, with ongoing strengths from our productizing vertical. Service revenues for the quarter were approximately 14.4% of revenue, up from prior periods and reflecting higher renewal activity.
International revenue for the quarter came in at $142 million or 27% of total revenue, down from 33% in the prior period. The lower international mix on a quarter over quarter basis primarily reflecting the timing of some cloud deployments and the inclusion of some larger in-region EMEA deals last quarter.
Our international base is still relatively small and we'll experience some volatility on a quarterly basis as the business develops. Overall gross margins in Q2 are 64.5%, up from 64.4% last quarter and above the midpoint of our guidance, up 62% to 64%. This outperformance versus guidance primarily reflected increased leverage on our fixed cost base in the quarter.
Operating expenses for the quarter were $143.9 million, up from $137.4 million last quarter. R&D spending came in at $92.3 million or 17.8% of revenue, up from $91.4 million in the prior period with increased headcount and related expenses. Sales and marketing expense was $39.9 million or 7.7% of revenue, up from $36.2 million last quarter, reflecting increased marketing and demo-related expenses. Our GAA costs included some legal and accounting fees associated with Mojo acquisition announced today.
Our operating income for the quarter was $191.2 million, or 36.8% of revenue. Other income and expense for the quarter was a favorable $6.9 million and our effective tax rate was 21.4%. This resulted in net income for the quarter of $155.7 million or 30% of revenue. Our diluted share number for the quarter was 80.8 million shares, resulting in a diluted earnings per share number of $1.93, up 44% from the prior year.
Legal expenses associated with the ongoing lawsuits came in at $3.6 million for the quarter. In addition, we recorded a $9.1 million impairment of our private company equity investments, projecting evaluation adjustments based on a recent funding lapse. Both of theses amounts are excluded from the non-GAAP results discussed above.
Now turning to the balance sheet, cash-cash equivalents and investments entered the quarter at approximately $1.9 billion. We generated $130.6 million of cash from operations in the June quarter. This reflects strong net income performance offset by changes in working capital requirements. DSOs came at 46 days, up from 39 in Q1, reflecting the timing of billings and collections in the quarter.
Inventory terms were 2.7 times, up from 2.2 in Q1 and inventory decreased to 245.4 million in the quarter, down from 268.1 million in the prior period. This reflects reductions primarily in finished goods as we continued to optimize our supply chain. In addition, we maintain the further 25.3 million of inventory deposits recorded in other assets compared to 24 million last quarter.
Our total deferred revenue balance was $448.6 million, down from $456.1 million in Q1. Product-deferred revenue declined by $15 million in the quarter, with customers completing final 945-related qualifications. At this point, we believed we've reached a somewhat normalized level of product-deferred revenue. While the underlying transactions will cycle on a quarter by quarter basis, the magnitude of the balance should stabilize. Accounts payable days were 26 days, down from 38 days in Q1, reflecting the timing of inventory receipts and payments. Capital expenditures in the quarter were $6.7 million.
Now turning to guidance -- as we look forward to the remainder of 2018, we believe that we are well-positioned to benefit from the continuing growth in cloud networking across our customer base. Our revenue guidance for the third quarter is consistent with our previous outlook, which calls for mid-20% revenue growth for the second half of the year.
The operations team is currently working to understand and attempt to mitigate any potential gross margin headwind related to the trade tariff announcement. We would ultimately look to pass on any un-remediated costs to customers.
We announced earlier today that we are acquiring Mojo Networks. This represents a small but strategic transaction which we expect to play an important role in our overall expansion into campus. We are just beginning the business and accounting integration and the acquisition will be recorded in our financials for the third quarter.
With this as a backdrop, our guidance for the third quarter, which is based on non-GAAP and excludes any non-cash stock-based compensation impacts and any legal costs associated with the ongoing lawsuits is as follows -- revenues of approximately $540 million to $552 million, gross margin of approximately 63% to 65%, operating margins of approximately 32% to 34%.
Our effective tax rate is expected to be approximately 21.5% with diluted shares of approximately 81.1 million. Please note that based on our current outlook, expect costs associated with ongoing to lawsuits to be approximately $6 million for the quarter.
Arista Networks, Inc. (ANET) Q2 2018 Earnings Conference Call Transcript -- The Motley Fool