I created a query to get sales sum for each month and I need to calculate difference between previous month and next month: SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, Salesdate), 0) AS TrendStartDate, SUM(Sales) AS TotalSales , LEAD(SUM(Sales), 1) OVER (PARTITION BY DATEADD(MONTH, DAT...
SQL Server date and time functions FunctionDescription GETDATE() Returns the current date and time DATEPART() Returns part of the date DATEDIFF() Calculates the difference between two dates SYSUTCDATETIME Returns the system date and time in UTC CONVERT() Converts date and time to different forma...
You can apply a simple aggregation first, and aggregate:
You can apply a simple aggregation first, and aggregate:
Yes, it's possible to compare SQL dates in T-SQL usingDATEDIFF(). This function calculates the difference between two dates in terms of a specified date part (such as days, months, or years). By comparing the result ofDATEDIFF()with a threshold value, you can determine if one date is...
To get a month name from a date, specify the date/timestamp as the first and “MONTH” as the second argument to the TO_CHAR() function.
And, to get last day of a month use: –LastDayPrevious/Current/NextMonthsSELECTDATEADD(DAY,-(DAY(GETDATE())),GETDATE()),'Last Day of Previous Month'UNIONALLSELECTDATEADD(MILLISECOND,-3,DATEADD(MONTH,DATEDIFF(MONTH,0,GETDATE()),0)),'Last Day of Previous Month (2)'UNIONALLSELECTDATEADD...
select count(*) from ordertable where 100*year(order_date)+month(order_date) = 100*year(curdate())+month(curdate()); Edited 1 time(s). Last edit at 10/24/2012 11:29AM by Peter Brawley. Sorry, you can't reply to this topic. It has been closed....
In my previous sql tip, we have seen how toget the week number of year. This time, we will see how to get the week umber of month. Finding week number in a month is not a straightforward way. There is no inbuilt function to get this. We have to create our own script using sever...
Query : db.getCollection('qaa').find({roll_no : {$gte : 0}},{_id : 0, roll_no : 1}) Index : db.getCollection('qaa').createIndex({roll_no : 1}) If the index here is in WT Internal Cache then it would be a straight forward process to get the values. An index...