Click here to Skip to main content
15,882,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
I deploy the website in IIS server. There is a problem in IIS server that is when I insert the sign in/out time of user when log out button is clicked, it stores the date time like 14/8/2012 but when I browse the website from IIS it stores the date time like ;14-8-2012.

So there are two different values stored in the database and from that I can not view the user`s log by date. Because in ajax calendar I set the format like 14/8/2012.

C#
Class1.sign_out=System.Convert.ToString(DateTime.Now);
                string s = "insert into User_log values('" + Session["user"].ToString() + "','" +string.Format("{0:dd/MM/YYYY}",Class1.sign_in)+ "','" + string.Format("{0:dd/MM/YYYY}",Class1.sign_out)+"'";
                SqlCommand cmd = new SqlCommand(s, c.getcon());
                cmd.ExecuteNonQuery();


So please help me.
Mitesh

[Edit - added code block]
Posted
Updated 2-Oct-20 20:29pm
v2
Comments
Rob Philpott 18-May-12 6:58am    
What SQL type are you using for the dates? String or datetime? Same with 'Class1'. what is sign_in and sign_out, strings or dates?
Herman<T>.Instance 18-May-12 7:34am    
what is the CultureInfo in IIS and what is the CultureInfo in your website?
[no name] 18-May-12 8:13am    
i use varchar datatype to store the datetime. there is three variable used in class that is sign_in,out and document_read.
Steve Maier 18-May-12 14:46pm    
is there a reason that the dates are not in datetime format? This would not be an issue if they used that type.

I think the root problem is that you use character data types for storing dates. I would advice not to do that, instead use datetime.

Another thing is that you concatenate the values for the SQL statement as literals in the statement. In order to prevent problems with data type conversions etc. use SqlParameter[^] instead
 
Share this answer
 
in C# whenever you need to explicitly define datetime format in following two cases
1. converting a datetime into string (that is ur case)
2. converting a string into date time.

so write the first line as below .

Class1.sign_out=System.Convert.ToString(DateTime.Now, new System.Globalization.DateTimeFormatInfo() { ShortDatePattern = "dd/MM/yyyy" });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900