Specific day of the current month and year

I have a problem returning a specific day of the current month and year. I need, for example, the 15th day. So far I have used the existing FB / IB function:

IB_EncodeDate(EXTRACT(YEAR FROM Current_Date),EXTRACT(Month FROM Current_Date),15) 

Is there an easy way to convert this for an MSSQL database?

to change. I need OLE output (41,348) to compare a date with another date. I compare the date with the database with the 15th day of the current month.

+4
source share
5 answers

During the 15th day of the current month:

 SELECT DATEADD(DAY, 14, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)); 

To get a silly OLE view based on this "magic" date, 1899-12-30:

 SELECT DATEDIFF(DAY, -2, DATEADD(DAY, 14, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0))); 

Answer (March 11th, when I updated this answer for the modified requirement):

 ----- 41348 
+5
source

So, do you have a date and want to return the 15th day of the same month ?. Well, assuming SQL Server 2008 you can do this:

 SELECT CONVERT(DATE,CONVERT(VARCHAR(6),GETDATE(),112)+'15',112) 

For previous versions of SQL Server:

 SELECT CONVERT(DATETIME,CONVERT(VARCHAR(6),GETDATE(),112)+'15',112) 
+2
source

This seems like a quick answer.

 declare @OLEDate int declare @currentDate as datetime set @currentDate = DATEADD(DAY, 14, DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)) set @OLEDate = convert(float, @currentdate) -- PRINT @OLEDate 

based on Aaron Bertrand's answer and your need for integer conversion

+1
source

Current_Date in SQL Server will be getdate() .

To get the 15th day in OLE Automation format, try:

 select datediff(day, '18991230', dateadd(day, -day(getdate()) + 15, getdate())) 
0
source

Not sure after Day or Date . This gives both dayOfWeek and specificDate for any culture.

 declare @myDay int = 15 select convert(date,myday) specificDate, datename(dw,myday) dayOfWeek from ( select convert(varchar(6),getdate(),112) + convert(varchar, @myDay) myday ) x 

Screenshot Demo here

 | SPECIFICDATE | DAYOFWEEK | ---------------------------- | 2013-02-15 | Friday | 
0
source

All Articles