Convert the whole date to string format - sql-server

I am working in sql query like this:
Display the STARTING_DATE in the following format – β€˜The fifth day of the month of
October, 2004’.
For example,
10-5-2004 should be displayed as'The fifth day of the month of October, 2004’

Use MySQL's DATE_FORMAT to format date.
SELECT DATE_FORMAT('2017-09-21', 'The %D day of the month of %M, %Y');
Output
The 21st day of the month of September, 2017

Related

Getting Month Names From Current Month to April

How can I get The months names from Current month to April only using SQL
Ex:-if the current month is July then I want the month names from July to April.
Current month should be the running month.
Any function or something like that....(I need to get the data from Db for those months)
This should work:
WITH Dates AS
(
SELECT GETDATE() D
UNION ALL
SELECT DATEADD(MONTH,1,D) FROM Dates WHERE DATEPART(MONTH,D)!=4
)
SELECT DATENAME(MONTH,D) [Month Name] FROM Dates
Result
Month Name
------------------------------
September
October
November
December
January
February
March
April

SQL Server: Set Date Range to be Between --> 10 years ago from today's date and 10/11/2017

I want to select a date range based on my "DTIN" column. I want my date range to be between two date values.
I want my DTIN dates to be between 10 years ago from today's date and a pre-set date of October 11th 2017.
Below is the line of code I tried but SQL Server tells me the AND statement is off.
WHERE [DTIN] BETWEEN (DATEADD(Year, -10, GETDATE()) AND (CONVERT(datetime, '2017-10-11'))
I am aware that my 10 year's ago from today's date is also off in the code above.

Week end Date in netezza

I am looking for week start and end date in Netezza but my week starts from Mon and ends on Sun
Date Week Start Date Week End Date
11/30/2015 11/30/2015 Mon 12/06/2015 Sun
Day of Week functions begin on Sunday in Netezza
Template Patterns
Extract Function
You'll need to use modulo in order to deal with Sunday.
select
current_date
,current_date - mod(extract(dow from current_date) - 2),7) week_start
,week_start + 6 week_end

SSIS - Modify date column from the 15th to the 1st of the month

SELECT * FROM [MarkTSK]
WHERE [MonthlyDt] IS NOT NULL
--AND
--SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)
Hello folks. Does anyone know how to correctly write this statement to
display the FIRST of each month? I have an Excel file that I am importing
into a Server using MS SSIS (VisualStudio 2008). The dates are monthly, but the last few months were the 15th June, May, April etc. My intent is to make
all of them show 1st of the month. All the months before January 2015 have been on the 1st of the month.
The SQL Query above is what I wrote in the Excel source Editor.
Thank You
This should always give you the first of the current Month
SELECT DATEADD(MONTH,DATEDIFF(MONTH,0,GETDATE()),0)
to pull back the first of the month for dates in your table something like this should do it
SELECT DATEADD(MONTH,DATEDIFF(MONTH,0,[MonthlyDt]),0) FROM [MarkTSK]
WHERE [MonthlyDt] IS NOT NULL
SELECT *, DATEADD('d',-DAY([MonthlyDT])+1, [Date]) AS [MonthD]
FROM [MarkTSK]
WHERE [MonthlyDT] IS NOT NULL
Thank you everyone. The SCRIPT above worked for me. All the dates that were not on the 1st of the month, now shows as the 1st.
Use DatePart to extract the Month and Year adding in the day manually.
Something like:
SELECT Convert(date, DatePart('yyyy', [MonthlyDt]) + DatePart('mm', [MonthlyDt]) + '01' ) FROM [MarkTSK]
WHERE [MarkTSK] IS NOT NULL
(Disclaimer: untested code)

Date search range previous month to current month

I had a working SQL date search...
(DATEADD (dd,-30, getdate()) <= pymnt_pstd_dt)
it gives me data from the past 30 days, but what I actually need is a comparison of the previous month MTD with the current month MTD
I am currently struggling with a good way to write that for SQL
Any help would be appreciated.
Here are WHERE statements that will get month to date and previous month to date for your field, pymnt_pstd_dt:
WHERE pymnt_pstd_dt BETWEEN DATEADD(month,DATEDIFF(MONTH,0,GETDATE()),0) AND GETDATE() --Month to date
WHERE pymnt_pstd_dt BETWEEN DATEADD(month,DATEDIFF(MONTH,0,GETDATE())-1,0) AND DATEADD(MONTH,-1,GETDATE()) --Previous month to date

Resources