SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) –First day of previous month SELECT DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1) –Last Day of previous month
Tag: get
How to get the Xth Day of the Week of the Year in C#
Let’s say we want to find the date of the first Friday of the 1st month. GetFirstFridayOfMonth(01.01.2023) =>06.01.2023 (The first Friday after 01.01.2023 is 06.01.2023) public DateTime GetFirstFridayOfMonth(DateTime date) { DateTime fridayDate = new DateTime(date.Year, date.Month, 1); //Let’s assume 1st Friday can start on the 1st of the month while (fridayDate.DayOfWeek != DayOfWeek.Friday) { fridayDate […]
How to get the first and last date of the current year in SQL
SELECT DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) AS StartOfYear, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, -1) AS LastDayOfYear, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, 0) AS FirstOfNextYear, DATEADD(ms, -3, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, 0)) AS LastTimeOfYear Thanks to Jamie F for the answer.
How to get ‘n’th row in Sql Query with OFFSET FETCH NEXT and ROW_NUMBER()
In SQL Server 2012+, you can use OFFSET…FETCH. The below query will help you to get 2nd row. But with little changes, you can get the ‘n’th row as well. SELECT <column(s)> FROM <table(s)> ORDER BY <sort column(s)> OFFSET 1 ROWS — Skip this number of rows FETCH NEXT 1 ROWS ONLY; — Return this […]
How to get stored procedure parameters details in SQL
select ‘Parameter_name’ = name, ‘Type’ = type_name(user_type_id), ‘Length’ = max_length, ‘Prec’ = case when type_name(system_type_id) = ‘uniqueidentifier’ then precision else OdbcPrec(system_type_id, max_length, precision) end, ‘Scale’ = OdbcScale(system_type_id, scale), ‘Param_order’ = parameter_id, ‘Collation’ = convert(sysname, case when system_type_id in (35, 99, 167, 175, 231, 239) then ServerProperty(‘collation’) end) from sys.parameters where object_id = object_id(‘MySchema.MyProcedureName’)
How to get triggers create and update date in SQL
SELECT o.name as [Trigger Name], CASE WHEN o.type = ‘TR’ THEN ‘SQL DML Trigger’ WHEN o.type = ‘TA’ THEN ‘DML Assembly Trigger’ END AS [Trigger Type], sc.name AS [Schema_Name], OBJECT_NAME(parent_object_id) as [Table Name], o.create_date [Trigger Create Date], o.modify_date [Trigger Modified Date] FROM sys.objects o INNER JOIN sys.schemas sc ON o.schema_id = sc.schema_id WHERE (type = […]
How to get session value in Javascript
<script> let mySession = ‘<%= Session[“SessionName”].ToString() %>’; //use your session … console.log(mySession); alert(mySession); </script>
How to get value from resx file in C#
// Gets the value of associated with key “MyKey” from the local resource file (“~/MyPage.aspx.en.resx”) or from the default one (“~/MyPage.aspx.resx”) //The default location for resx files is App_LocalResources object keyValue = HttpContext.GetLocalResourceObject(“~/MyPage.aspx”, “MyKey”);
Getting index value in Razor ForEach
@{int i = 0;} @foreach(var myItem in Model.Members) { <span>@i</span> @{i++;} }
Getting Session value in Javascript & Asp.Net
<script> var mySessionValue = ‘<%= Session[“SessionName”].ToString() %>’; alert(mySessionValue); </script>
How to split string and get first (or n-th) value only
string myValueToSplit = “Istanbul, Tokyo, Seoul, Bangkok, Bali, Minsk, Belgrade, Kiev”; var theFirstValue = myValueToSplit.Split(‘,’)[0]; //OUTPUT: theFirstValue = “Istanbul” //You can change [0] as you wish. //For example, if you want to get Kiev, make it [7]
How to use and get HiddenField Value in Gridview
You can add HiddenField to the Gridview like that:
Get the row number “x” from SQL
WITH Records AS (SELECT ROW_NUMBER() OVER(ORDER BY ID_of_your_SQLTable) AS ‘ROW’, * FROM yourSQLTable) SELECT * FROM Records WHERE ROW = X –You can change X with the number you wanna get (For Example ROW = 5 will bring the 5th record)