How Use the datefromparts

Hello Community,

I'm not sure if this the right group to ask about sql question not related to T-SQL.

Can someone show me how to modify the following sql query so that I can view the day of the month for the Date column?

I tried the following query but it failed:

SELECT
DATEFROMPARTS(appl_stock.Date, @Month) AS expr1
FROM dbo.appl_stock

The table looks like the following:

table

Any thoughts will be greatly appreciated.

Thanks

I'm not sure you need to use the DATEFROMPARTS function here. To see the date in a specific format, you use CONVERT or FORMAT. CONVERT will work in any version of SQL Server.

SELECT
CONVERT(varchar(10), appl_stock.Date, 101) AS Date
FROM dbo.appl_stock

select datepart(day,[date]) as expr1
  from dbo.appl_stock

or

select day([date]) as expr1
  from dbo.appl_stock

Thanks guys for reaching out.

I'm sure if it matters, but I created the SQL query using a SQL query tool called, 'dbforge Studio for SQL Server'.

SELECT
DATEFROMPARTS(appl_stock.Date, @Month) AS expr1
FROM dbo.appl_stock

I will try the suggestion:

select datepart(day,[date]) as expr1
from dbo.appl_stock

Guys,

How do you know when to use DATEFROMPARTS or datepart?

Thanks

You use DATEFROMPARTS to construct a DATE FROM its PARTS. For example
SELECT DATEFROMPARTS(2018,12,31)

DATEPART gets you a part of the date if you already have a date.
SELECT DATEPART(DAY, '20181231')

What is not obvious from my example is that the result of the first select is of type DATE and the inputs given to it are integers. The result of the second select is an INTEGER, and it takes a DATE as the parameters (converting the string to a DATE and then using it)

Thanks JamesK