December 16, 2018 at 11:14 am
I need query (in my case an INSERT) to run only if today's date is 3rd day of Calendar Month?
how to get date precisions for to exclude minutes on right side of the IF?
IF CONVERT(VARCHAR(10), GETDATE(), 112) = cast(DATEADD(month, DATEDIFF(month, 0, getdate()), 2) AS smalldatetime)
SELECT 1 + 1
ELSE
select 0
how to get date precisions for to exclude minutes on right side of the IF?
--Quote me
December 16, 2018 at 11:26 am
polkadot - Sunday, December 16, 2018 11:14 AMI need query (in my case an INSERT) to run only if today's date is 3rd day of Calendar Month?
how to get date precisions for to exclude minutes on right side of the IF?
IF CONVERT(VARCHAR(10), GETDATE(), 112) = cast(DATEADD(month, DATEDIFF(month, 0, getdate()), 2) AS smalldatetime)
SELECT 1 + 1
ELSE
select 0how to get date precisions for to exclude minutes on right side of the IF?
You should have a look at the functionality of DATEPART.
IF DATEPART(dd,GETDATE()) = 3
SELECT 1 + 1
ELSE
SELECT 0
;
--Jeff Moden
Change is inevitable... Change for the better is not.
December 16, 2018 at 11:48 am
For more info on DATEPART, please see the article at the following link.
https://docs.microsoft.com/en-us/sql/t-sql/functions/datepart-transact-sql?view=sql-server-2017
There's also a wealth of knowledge just a click away in the menu on the left of that article.
There are also a ton of "date/time" tricks that you can do with dates and times like finding the first day of the given month as provided by GETDATE() or some data stored in a column. Since temporal data manipulation is so very important in databases, I strongly recommend that you learn what all of the "Date and Time Functions" are in SQL Server and mostly memorize them. The link I provided is just scratching the surface of what you can actually do.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply