SQL Server: [code lang=”sql”] select top 10 * from my_table where CONVERT(varchar, my_date_time, 101) BETWEEN ’08/27/2020′ AND ’09/21/2020′ and CONVERT(varchar, my_date_time, 108) BETWEEN ’05:00:00′ AND ’19:00:00′ and DATEPART(day, my_date_time) BETWEEN 2 AND 4 [/code] Result: SQL contains between 08/27/2020 and 09/21/2020 and 05:00 and 19:00 and Tuesday and Thursday’s records [code lang=”sql”] SELECT * FROM my_table WHERE DATEPART(hh, [my_date_time]) >= 6 AND DATEPART(hh, [my_date_time]) <= 22 [/code] Result: SQL contains between 06:00 and 22:00 records Date to Text: [code lang=”sql”] DECLARE @StartDate datetime ,@EndDate datetime; SELECT @StartDate = GETDATE()-8; CONVERT(varchar, FORMAT (@StartDate, ‘yyyy-MM-dd’), 101) [/code] Output: 2021-03-23 [code lang=”sql”] @SomeText nvarchar(max) = ‘Some text’ + cast(cast(GETDATE() as date) as varchar(64)); –OR @SomeTxt nvarchar(max) = ‘Some text’ + convert(varchar(10), GETDATE(), 101); [/code] For more information visit below sites: microsoft.com datepart-transact-sql tableplus.com convert-varchar-to-date-sql]]>

Leave a Reply

Your email address will not be published. Required fields are marked *