-
SQL query for today’s date minus year, month, day or minute
To add or subtract some date/time you can use MS SQL function: DATEADD(datepart, number, date) Let's say you need to add five months to current date, use this: SELECT * FROM YourTable WHERE YourDate < DATEADD(month, 5, GETDATE()) I used function GETDATE() for getting current DateTime. If you need to subtract some time, just add… -
Start of month from date in MS SQL (opposite to EOMONTH function)
Sometimes we need to select values grouped by month from MS SQL Table. Probably the easiest way to do it is to call function DateAdd with DateDiff: SELECT Sum(YourColumn), DATEADD(month, DATEDIFF(month, 0, [YourDateColumn]), 0) as 'Date' FROM YourTable GROUP BY DATEADD(month, DATEDIFF(month, 0, [YourDateColumn]), 0); Or we can use EOMONTH function that give us date that is…
Loading posts...