Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 ASP.NET
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 24-Mar-13 21:40pm
Comments
hemantrautela at 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 at 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
hemantrautela at 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....
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this:
 
DateTime uploadedOn = DateTime.ParseExact("1/9/2009", "M/d/yyyy", new CultureInfo("en-US"));
  Permalink  
v2
Comments
Rickin Kane at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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..
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.150302.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100