Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys ,

i agree its a lame question and can get lots of resource online via google , i really want to find the correct answer as it really driving me nuts

The scenario is , i need to set & save & display the datetime to dd/MM/yyyy , i have already change the culture to en-US and the Dateformat to dd/MM/yyyy in the production server and have via code i am passing the below code

DateTime uploadedOn = DateTime.ParseExact(System.DateTime.Now.ToShortDateString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);

drDocuments["UploadedOn"] = uploadedOn.ToShortDateString();


whenever i try on my developement system it works and assuming that its fixed , i deploy to uat and production , but there is giving the error
Input string is not a valid datetime


i have made sure that regional settings on both the machine my developement and production server are same , can anybody please advise where i am going wrong , or any suggestion or adivce which will help me to overcome the issue, please , really need experts help , i have surrendered and finally turned to expert opinion , Hope CP Members can help
Posted
Comments
Hemant Singh Rautela 25-Mar-13 3:09am    
use this only...(default date time format in sql is- mm/dd/yyyy, so that you getting error )
DateTime uploadedOn = System.DateTime.Now;
drDocuments["UploadedOn"] = uploadedOn.ToString();
Rickin Kane 25-Mar-13 3:16am    
hi hemant

thanks for your reply , but the same code is working on my development machine , even if i connect to production DB
and the code is not even talking to DB at the moment , i am storing it in Dataset and then passing dataset to DB , i am getting error , by the time i am trying to fill the dataset with my uploaded file information
Hemant Singh Rautela 25-Mar-13 3:30am    
just try at your machine, use date greater than 12 like 15/12/2012 & check it,

I think no need to convert to another format why not use default format(mm/dd/yyyy) as i replied earlier because sql datetime format is mm/dd/yyyy no need to change .. ya when you retrieve to show then you can change formant for showing on your application....

Try this:

C#
DateTime uploadedOn = DateTime.ParseExact("1/9/2009", "M/d/yyyy", new CultureInfo("en-US"));
 
Share this answer
 
v2
Comments
Rickin Kane 25-Mar-13 3:30am    
i need to set the date in dd/MM/yyyy format only , m/d/yyyy will not work as per users requirement , they need it in dd/MM/yyyy
hi buddy try it once

DateTime uploadedOn = DateTime.ParseExact(System.DateTime.Now.ToString("MM/dd/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture);

drDocuments["UploadedOn"] = uploadedOn.ToShortDateString();


default date time format in sql is- mm/dd/yyyy, so that you getting error
May it solve ur problem..
 
Share this answer
 

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

  Print Answers RSS


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