0
string Edate = collection["effectiveDatePicker"].ToString();
string Cdate = collection["cancelDatePicker"].ToString();

The Date I am getting is 20101112 or 20101116

Then I am doign soemthign like this to assing my Datetime variable

h.Edate= DateTime.ParseExact(collection["effectiveDatePicker"].ToString(), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture, DateTimeStyles.NoCurrentDateDefault);
                        h.CDate= DateTime.ParseExact(collection["cancelDatePicker"].ToString(), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCult

After saving to the data base.. I am seeing the EDate and CDate fileds somethign like this

11/10/2010
11/15/2010

with the same dates when I Submit again I am getting Error in the ParseExact bec the string I am getting is 11/10/2010 but its expecting 20101010

Can any body help me out?

3 Answers 3

2

You can specify the format that your dates are coming in as like this:

string Edate = collection["effectiveDatePicker"].ToString("yyyyMMdd");
string Cdate = collection["cancelDatePicker"].ToString("yyyyMMdd");

This should ensure that you are working with strings that look like what you want.

Sign up to request clarification or add additional context in comments.

4 Comments

I am getting the Error System.Iformateprovider on this Lines if I use this line of code.. thanks
How is the collection declared? You may need to cast collection["effectiveDatePicker"] as a date object first, before calling ToString().
Sounds like the problem is where you are actually adding these values to the collection. Make sure that what you are adding are the actual DateTime objects (or strings stored in a specific format that you will know). If they are DateTime objects already, there should be no need to do the ExactParse().
Then ensure that you are adding it in "yyyyMMdd" format. It seems like you are adding in "MM/dd/yyyy" format.
1

I can tell you for sure that there is a reformatting problem. I don't fully understand your code and the steps it takes (I guess you are using data binding or something similar).

The point seems that dates are initially set as yyyyMMdd, but when you postback the ToString() operator is applied to these dates, converting them to your OS's native format MM/dd/yyyy.

You must force them to be converted into yyyyMMdd again, because by default ToString will use CurrentUICulture which is not good for you.

You should show us the update code

Comments

0

I'm not sure what your specific question is. Because you're using DateTime.ParseExact() and are specifying a format of 'yyyyMMdd', passing in a string such as '11/04/2010' will fail.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.