Working with Date - C#

PAtrykkp

Новичок
Регистрация
01.10.2016
Сообщения
19
Благодарностей
2
Баллы
3
Hello,
In my project i save current date. Then i need to check is this saved date is older than current date, i write below code but its not working:

// here i have saved data example: 2017-04-22 10:22:43
var zapisanadatax = project.Variables["fora_creation_date"].Value;

var zapisanadata = System.DateTime.ParseExact(zapisanadatax, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

int wynik = 11;
if (zapisanadata < System.DateTime.Now) {
wynik = 1;
} else {
wynik = 0;
}

return wynik;

But when i run this code - project show error. Red X.
Can somebody check this code ? System.DateTime.Now is also in this format: yyyy-MM-dd HH:mm:ss
 

Geograph

Client
Регистрация
16.02.2014
Сообщения
209
Благодарностей
113
Баллы
43
Код:
  var currentDate = DateTime.Now;
  var otherDate = DateTime.Parse("2017-01-01");
  //var otherDate = DateTime.Parse("2018-01-01");
  if (other < currentDate)
  {
    MessageBox.Show("Older");
  }
  else
  {
    MessageBox.Show("Newer");
  }
 

arhip1985

Client
Регистрация
31.10.2011
Сообщения
2 955
Благодарностей
781
Баллы
113
Hello,
In my project i save current date. Then i need to check is this saved date is older than current date, i write below code but its not working:

// here i have saved data example: 2017-04-22 10:22:43
var zapisanadatax = project.Variables["fora_creation_date"].Value;

var zapisanadata = System.DateTime.ParseExact(zapisanadatax, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

int wynik = 11;
if (zapisanadata < System.DateTime.Now) {
wynik = 1;
} else {
wynik = 0;
}

return wynik;

But when i run this code - project show error. Red X.
Can somebody check this code ? System.DateTime.Now is also in this format: yyyy-MM-dd HH:mm:ss
I think - this kod is working, may be mistake in other
 

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 218
Благодарностей
5 843
Баллы
113
Hello,
In my project i save current date. Then i need to check is this saved date is older than current date, i write below code but its not working:

// here i have saved data example: 2017-04-22 10:22:43
var zapisanadatax = project.Variables["fora_creation_date"].Value;

var zapisanadata = System.DateTime.ParseExact(zapisanadatax, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

int wynik = 11;
if (zapisanadata < System.DateTime.Now) {
wynik = 1;
} else {
wynik = 0;
}

return wynik;

But when i run this code - project show error. Red X.
Can somebody check this code ? System.DateTime.Now is also in this format: yyyy-MM-dd HH:mm:ss
What exact error do you get? Please attach screenshot of error in log:
PM_log.png
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)