You should have Logindetails table.
You can do this in 2 way
First way
Insert new record everytime the user logins and get the min(time ) for that particular day.
This is kind of history so you can keep track of every login
Second way:
Insert new record when user logins first time for the day. If user tries to login second time, go and check whether a record already exists for that particular day and for particular user . If it exists dont insert.
So now you will have only one login time per day per user. No history tracking.
if not exists(select 1 from logintable
where CONVERT(varchar(8), logindate, 112) =CONVERT(varchar(8), GETDATE(), 112) and Id=1)
insert into logintable(col1,col2,col3,logindate) values (val1,val2,val3,getdate())
updated solution, based on the comments.
protected void Button2_Click(object sender, EventArgs e)
{
string intime = DateTime.Now.ToString();
string ID = Session["Name"].ToString();
string indate = DateTime.Now.ToShortDateString();
SqlConnection cn = new SqlConnection("Data Source=Sony-VAIO\\MSSQLSERVER2008;InitialCatalog=db;Integrated Security=True");
cn.Open();
SqlCommand cmd = new SqlCommand(@"if not exists (select 1 from intime where convert(varchar(30),indate,112)=convert(varchar(30),getdate(),112) and Id=@Id) insert into intime
values ('" + ID + "','" + intime + "','" + indate + "')", cn);
cmd.Parameters.AddWithValue("@Id", ID);
cmd.ExecuteNonQuery();
cn.Close();
}