Simplest way to calculate first and last day of month and week for specific date in MS Sql Server

I have come up with following few lines that illustrate a way to find first and last day(date) for specified date.

And then given same thing for week.

Declare @SpecifiedDate DateTime;
Set @SpecifiedDate=GETDATE();
Declare @XStart int;
Set @XStart=0;

SELECT @XStart=DATEDIFF(mm,0,@SpecifiedDate)
SELECT DATEADD(mm,@XStart,0) ‘First Day of Specific Month’
SELECT DATEADD(d,-1,DATEADD(mm,@XStart+1,0)) ‘Last Day of Specific Month’

SELECT DATEADD(wk,DATEDIFF(wk,0,@SpecifiedDate ),0) ‘First Day of Week’
SELECT DATEADD(wk,DATEDIFF(wk,0,@SpecifiedDate ),6) ‘Last Day of Week’


Happy New Year of 2014 to all visitors of my technical blog.

Hello All Readers,

As we all are migrating to new year. I personally feel this new year will give us chance to make new starting for application of new idea in our life and we forgot mistakes and learn from our experience.

And hope god will help us to lead to more bright future and give direction to outcome from trouble.

And as usual technology will go to next step in all phase of life and let we keep moving ahead with it.

Sticky Div, Area that remains at top on scroll of page

If you want your site header or  menu or other section(div) to remain at top of page when user scrolls a page. You can try with following jquery code.

It will not workin in IE. So first flag need check if browser is IE or not.

if (!IsIE) {
jQuery(document).ready(function() {
function SomeScrollResponder() {
var tmpScroll = $(window).scrollTop();

//when page scrolls 100 px then following  code will run
if (parseInt(tmpScroll) > 100) {
jQuery(“#divTop”).css(“position”, “absolute”);
jQuery(“#divTop”).css(“top”, (parseInt(tmpScroll) – 1) + “px”);  //-1 will hide top border
jQuery(“#divTop”).css(“width”, (parseInt($(document).width()) – 60) + “px”);

else {
jQuery(“#divTop”).css(“position”, “relative”);
jQuery(“#divTop”).css(“top”, “0px”);

In above example “divTop” is a div that will display at top, overlapping on page.


Embed Gujarati font in website / Embed any other font in web page

Use following definition, which is pointing to a font file located on web server, and a class that has ‘font-family’ attribute with your custom defined font.

font-family: “myguj-font”;
src: url(“Gujrati-Saral-1.ttf”) format(“truetype”);
font-weight: normal;
font-style: normal;
font-family: “myguj-font”;

And your display area need just to point to a style class as follow:

<div class='myguj'>
This text will appear in Gujarati Font.

Find and download TTF, EOT, SVG, WOFF kind of font files and save in web folder, then you can refer via style sheet(css) file and embed any kind of font in your web page.

My personal website Siddharth Borania’s Personal Website

Output parameter in stored procedure with ExecuteReader method

Conventionally ExecuteReader method is used for returning DataReader object.

Which in turn you can use to fill DataTable.

What if you want a DataTable and some return argument from your stored procedure?

One way is explained below.

Your stored procedure will have one OUTPUT parameter , that will give you number returned form database:


@Keyword nvarchar(20),



Select * from product where productname like ‘%’ + @Keyword  + ‘%’

Select @CNT=count(*) from product where productname like ‘%’ + @Keyword  + ‘%’


And in ASP.Net Code should be like:

Int32 intCNT;

DataTable xTbl = new DataTable();

using (SqlConnection conn = new SqlConnection(connectionString))  


SqlCommand cmd= new SqlCommand();

cmd.Connection = conn;

cmd.CommandType= CommandType.StoredProcedure;

cmd.CommandText = “GETPRODUCTS”;


SqlParameter[]  tmpParam = new SqlParameter[] {

                new SqlParameter(“@keyword”, SqlDbType.NVarChar,20),

                new SqlParameter(“@CNT”, SqlDbType.Int)};


                tmpParam [0].Value =”test”;

                tmpParam [1].Direction = ParameterDirection.Output;



SqlDataReader rdr =cmd.ExecuteReader(CommandBehavior.CloseConnection);

                if (rdr.HasRows)

                {  xTbl.Load(rdr);  }


                intCNT = int.Parse(cmd.Parameters[1].Value.ToString());


Make sure you CLOSE data reader object before retrieving values from parameter.

So here you will get DataTable with records from data base  and Integer variable (intCNT)  with record count from same table.


Other Technical Stuff from Siddharth:

Show current date using Javascript in web browser(Client side date in web browser


How to make custom Task Scheduler in c# using thread


Introduction to Andriod – First step towards Andriod application development