Problem in Date Format
-
Hi, I have developed an web page.In which there is a textbox for date entry and the entry format is dd/MM/yyyy. Somewhere in my code I am converting this textbox value to datetime.e.g: Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime". Can anyone help me out!! Thnaks and regards
ARINDAM
-
Hi, I have developed an web page.In which there is a textbox for date entry and the entry format is dd/MM/yyyy. Somewhere in my code I am converting this textbox value to datetime.e.g: Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime". Can anyone help me out!! Thnaks and regards
ARINDAM
ARINDAM1981 wrote:
Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime".
What input are you giving for the text?
cheers, Abhijit CodeProject MVP
-
ARINDAM1981 wrote:
Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime".
What input are you giving for the text?
cheers, Abhijit CodeProject MVP
the input in my text is exactly as the following 16/04/2009
ARINDAM
-
the input in my text is exactly as the following 16/04/2009
ARINDAM
ARINDAM1981 wrote:
the input in my text is exactly as the following 16/04/2009
if the input is same for both case check the date time settings on server, weather it is dd/mm/yyyy or mm/dd/yyyy. I will suggest you to use
DateTime.Parse()
and use CurrentCulterinfo
for the convertion.cheers, Abhijit CodeProject MVP
-
Hi, I have developed an web page.In which there is a textbox for date entry and the entry format is dd/MM/yyyy. Somewhere in my code I am converting this textbox value to datetime.e.g: Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime". Can anyone help me out!! Thnaks and regards
ARINDAM
create the date column in Datetime type.... eg create table tablename(date datetime)
-
create the date column in Datetime type.... eg create table tablename(date datetime)
nithydurai wrote:
create the date column in Datetime type.... eg create table tablename(date datetime)
What is the relation between the Question and your answer?:confused:
cheers, Abhijit CodeProject MVP
-
nithydurai wrote:
create the date column in Datetime type.... eg create table tablename(date datetime)
What is the relation between the Question and your answer?:confused:
cheers, Abhijit CodeProject MVP
i think u are create the date column in string format....
-
Hi, I have developed an web page.In which there is a textbox for date entry and the entry format is dd/MM/yyyy. Somewhere in my code I am converting this textbox value to datetime.e.g: Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime". Can anyone help me out!! Thnaks and regards
ARINDAM
Hi, try this textbox1.text = string.format("{0:G}",datetime.now); or visit this http://codeincsharp.blogspot.com/2008/05/different-date-format-in-c.html Hope this one can help. Thanks Hi, Please select Good Question if my answer are fit to your Question.
modified on Tuesday, April 28, 2009 3:07 AM
-
Hi, try this textbox1.text = string.format("{0:G}",datetime.now); or visit this http://codeincsharp.blogspot.com/2008/05/different-date-format-in-c.html Hope this one can help. Thanks Hi, Please select Good Question if my answer are fit to your Question.
modified on Tuesday, April 28, 2009 3:07 AM
Your post is breaking the formatting. Please post the link properly. Thank you.
cheers, Abhijit CodeProject MVP
-
Hi, I have developed an web page.In which there is a textbox for date entry and the entry format is dd/MM/yyyy. Somewhere in my code I am converting this textbox value to datetime.e.g: Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime". Can anyone help me out!! Thnaks and regards
ARINDAM
Hi, Try using this code, this is a bit lengthy work but is useful in these type of cases.
// First Split the Textbox text on '/' string[] arrdate = textbox1.Text.Split('/'); //Get the Splitted values in variable, You can also use them directly in the followed statement used to create DateTime. int year = Convert.ToInt32(arrdate[2].ToString()); int month = Convert.ToInt32(arrdate[1].ToString()); int day = Convert.ToInt32(arrdate[0].ToString()); // Now create a new Datetime variable DateTime myDt = new DateTime(year, month, day); // Or you can write like this DateTime myDt = new DateTime(Convert.ToInt32(arrdate[2].ToString()), Convert.ToInt32(arrdate[1].ToString()), Convert.ToInt32(arrdate[0].ToString())); // Here is you Datetime variable.
Regards, Kaushal Arora Please mark as Answer if it solved your problem.