what am I doing wrong on this?

this giving me error I dont know how to correct it
if (DateTime.Parse(_reader2["dueDate"].ToString()) = "1/1/1980")
                            rdpProjectDetailsDueDate.SelectedDate = ""
                        else
                        rdpProjectDetailsDueDate.SelectedDate = DateTime.Parse(_reader2["dueDate"].ToString());

Open in new window

1jawsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

silemoneCommented:
instead of DateTime.Parse, Try Convert.ToDateTime
if (DateTime.Parse(_reader2["dueDate"].ToString()) = "1/1/1980")
                            rdpProjectDetailsDueDate.SelectedDate = ""
                        else
                        rdpProjectDetailsDueDate.SelectedDate = DateTime.Parse(_reader2["dueDate"].ToString());

Open in new window

0
p_davisCommented:
what is the error and where does it occur  are you sure that those are always dates -- you might want to use DateTime.TryParse
0
silemoneCommented:
Use a try/catch block also
try
{
if (Convert.ToDateTIme(_reader2["dueDate"].ToString()) = "1/1/1980")
                            rdpProjectDetailsDueDate.SelectedDate = ""
                        else
                        rdpProjectDetailsDueDate.SelectedDate = Convert.ToDateTime(_reader2["dueDate"].ToString());
}
catch(Exception ex)
{
   string strErr = ex.StackTrace.ToString()  //<--put a breakpoint here and see what it says if exception happens
}

Open in new window

0
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Fernando SotoRetiredCommented:
DateTime.Parse takes a string paraneter of a date and returns a DateTime object and then you try to assign a string to it in a if statement. Something like this would check to see is the two are equal.

if (DateTime.Parse(_reader2[0].ToString()) == DateTime.Parse("1/1/1980"))
0
1jawsAuthor Commented:
Thank you all for replying, I have tried all the suggestions and only fernando's actually give me least error..
That is the error highlighing  ""  
Cannot implicitly convert type 'string' to 'System.DateTime?'      

can I put something else to that to empty the date textbox of the calendar and show no date? I thought "" would empty it but complaining..


 if (DateTime.Parse(_reader2["dueDate"].ToString()) == DateTime.Parse("1/1/1980"))
 
                            rdpProjectDetailsDueDate.SelectedDate = "";
                        else
                            rdpProjectDetailsDueDate.SelectedDate = DateTime.Parse(_reader2["dueDate"].ToString());

Open in new window

0
p_davisCommented:
"" is a string not a date --does the date text box have a null value property? or a text property? you could use those instead of setting selecteddate which i would assume needs a date and not an empty string
0
1jawsAuthor Commented:
<radCln:RadDatePicker ID="rdpProjectDetailsDueDate" runat="server" Width="100px">
                                        <Calendar ID="Calendar1" Skin="WebBlue" runat="server" />
                                    </radCln:RadDatePicker>
0
Fernando SotoRetiredCommented:
You can not assign a string value to an object of type DateTime as in the following statement. You have to decide on what date to assign to rdpProjectDetailsDueDate.SelectedDate when the if statement is true and then assign a date object to it as you do in the else part of the if statement.

rdpProjectDetailsDueDate.SelectedDate = "";
0
1jawsAuthor Commented:
ok it is really weird  if (DateTime.Parse(_reader2["dueDate"].ToString()) == DateTime.Parse("1/1/1980"))
left side is not showing it is equal to 1/1/1980  it jumps after else and that time though rdpProjectDetailsDueDate.DbSelectedDate = to 1/1/1980
I got this values when I do debug and see



if (DateTime.Parse(_reader2["dueDate"].ToString()) == DateTime.Parse("1/1/1980"))

                            rdpProjectDetailsDueDate.DbSelectedDate = "";
                        else
                            rdpProjectDetailsDueDate.DbSelectedDate = DateTime.Parse(_reader2["dueDate"].ToString());
0
p_davisCommented:
if you are just looking for the date you should just compare the date

if (DateTime.Parse(_reader2["dueDate"].ToString()).Date == DateTime.Parse("1/1/1980")).Date
0
1jawsAuthor Commented:
didnt work
0
1jawsAuthor Commented:
Argghhhh! this is sooo frustrating!!
0
1jawsAuthor Commented:
all I want to show the textbox of the calendar to Empty if value of the date is Null on the db. THat's it
but keep puting 1/1/1980 because that is telerik's default if it is null. It is crazy.
0
p_davisCommented:
are there any events that you can override?
0
1jawsAuthor Commented:
I am not sure p davis...

here the link I found and reviewed but that is not solving my problem,
http://www.telerik.com/community/forums/aspnet/calendar/date-picker-null-problems.aspx
0
AruspexCommented:
i would suggest something like the following hope it helps
DateTime dueDate;
        DateTime compareDate;
 
        if (!string.IsNullOrEmpty(_reader2["dueDate"].ToString()))
        {
            if (DateTime.TryParse(_reader2["dueDate"].ToString(),out dueDate) && 
                DateTime.TryParse("1/1/1980",out compareDate))
            {
                if (dueDate.CompareTo(compareDate) == 0)
                    rdpProjectDetailsDueDate.SelectedDate = "";
                else
                    rdpProjectDetailsDueDate.SelectedDate = dueDate;
            }
        }

Open in new window

0
1jawsAuthor Commented:
I got this eror Cannot implicitly convert type 'string' to 'System.DateTime?' for this   ""       
0
p_davisCommented:
you need to set it to null then not ""
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
p_davisCommented:
System.DateTime? is a nullable DateTime so either a date or a null value are acceptable, nothing else.
0
1jawsAuthor Commented:
DBNull ?
0
p_davisCommented:
no -- just

null


0
1jawsAuthor Commented:
no error but still seeing 1/1/1980 on the textbox !!!
0
p_davisCommented:
instead of selected date try using DbSelectedDate  and setting that to null
0
1jawsAuthor Commented:
still no! I even put AllowEmpty = "true" this aspx page, still, it is funny duedate comes as a 1/1/1900 and when puttin the text box it puts 1/1/1980  it is insane!!!
0
Fernando SotoRetiredCommented:
Hi 1jaws;

I have done a little research and found that the cuurent version of Telerik DateTimePicker SelectedDate is of the Nullable type and therefore accepts a value of null. the below code snippet should work.

if (DateTime.Parse(_reader2["dueDate"].ToString())Date == DateTime.Parse("1/1/1980").Date)
    rdpProjectDetailsDueDate.SelectedDate = null;
else
    rdpProjectDetailsDueDate.SelectedDate = DateTime.Parse(_reader2["dueDate"].ToString());

Fernando
0
1jawsAuthor Commented:
arghhh! thank you for researching Fernando, didnt work, still puts 1/1/1980
0
1jawsAuthor Commented:
on left side betweeen ()) Date, I had to put . is that ok? otherwise giving problem..
0
Fernando SotoRetiredCommented:
Please place this line of code just before the if statement and post its results here.
Responce.WriteLine(_reader2["dueDate"].ToString());
0
Fernando SotoRetiredCommented:
Yes it should be this.
if (DateTime.Parse(_reader2["dueDate"].ToString()).Date == DateTime.Parse("1/1/1980").Date)
0
1jawsAuthor Commented:
yes, I did that still didnt work. I am so stuck with this..Droves me crazy..
0
Fernando SotoRetiredCommented:
What was printed out as the value for _reader2["dueDate"].ToString() ?
0
M3mph15Commented:
Hi,

Try doing it in steps.

DateTime aDate As DateTime = _reader2["dueDate"];
String sDate = aDate.ToString("dd/MM/yyyy");
if (sDate = "1/1/1980" Or sDate.Length = 0)
                        rdpProjectDetailsDueDate.SelectedDate = "";
else
                        rdpProjectDetailsDueDate.SelectedDate = aDate; //(Not 100% on using aDate here. Either aDate or sDate)

Hope this helps
-M3mph15
0
1jawsAuthor Commented:
I wish we have a lightbulb icon here, because this is exacly happened to me, I was keep checking agains 1/1/1980 instead of that I needed to check 1/1/1900 because that is comes from the db to compare, then if this is 1/1/1900 it assignes to that 1/1/1980.. So thank you so much for all the replies, everybody deserved points, just special thanks to p_davis and the fernando, they keep followed up the my questions thru...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.