0

i have a problem that i am saving the value in database DatetimePicker.Value.Day(which returns Int); now i am getting this value on another form on

label.Text = DataGridViewName.Rows[0].Cells["ColumnName"] +"-"+System.DateTime.Now.ToString("dd-MM-yyyy");

now i want to compare the value of label.Text with current date ... so i have to convert the label.text into datetime

DateTime DueDate = DateTime.ParseExact(Label.Text, "dd-MM-yyyy",null);

OR

Convert.ToDatetime(label.text);

but both conversion gives me error of String is not Valid and geirgian calender ERROR i cannot understand what to do

  • You can convert it by DateTime DueDate = DateTime.ParseExact(Label.Text, "dd-MM-yyyy",CultureInfo.InvarientCulture); – Shashank Jan 29 '14 at 06:33
  • i found a similar question [here](http://stackoverflow.com/questions/14851285/how-to-get-datepicker-value-in-date-format) He converts it into string and get the date format – Abhinav Jan 29 '14 at 06:35
  • @Shashank , you should turn your comment as answer :) Take some reputations ! – zey Jan 29 '14 at 07:13
  • @Dani Danish: I have added my answer. You can accept it. – Shashank Jan 29 '14 at 08:31

2 Answers2

0

You can convert it by

DateTime DueDate = DateTime.ParseExact(Label.Text, "dd-MM-yyyy",CultureInfo.InvarientCulture);
Shashank
  • 401
  • 2
  • 13
0
string s = lblDueDate.Text;
                    DateTime DueDate = DateTime.ParseExact(s, "MM-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None);

Here lblDueDate.Text has Date which i have stored from database and then i have convert lblDueDate.Text in DateTime for comparing this Date from Current Date

Florian
  • 5,918
  • 3
  • 47
  • 86