Date puzzle

shabbysquire

Client
Регистрация
25.11.2012
Сообщения
544
Благодарностей
26
Баллы
28
Just a question re dates, and how to calculate the number of days that have lapsed.

I download a .csv file, and the date format is always:

01-Dec-15

Is it possible to

1) Get ZP to understand the date? Maybe regex it, and then put it into a format that ZP understands.

2) Then work out how many days have passed, ie from 01 Dec 15 to now?

Thanks.
 

AloneSlamer

Client
Регистрация
29.01.2013
Сообщения
1 404
Благодарностей
362
Баллы
83

Обращаем Ваше внимание на то, что данный пользователь заблокирован.
Не рекомендуем проводить с AloneSlamer какие-либо сделки.

convert date in you format after use date as you wish if not please contact me in Skype life9o9 will help for a small fee if it doesn't take a lot of time
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 812
Благодарностей
1 187
Баллы
113
C#:
string someDate = "01-Dec-15";
// 1.
// Parse the date and put in DateTime object.
DateTime startDate = DateTime.Parse(someDate);

// 2.
// Get the current DateTime.
DateTime now = DateTime.Now;

// 3.
// Get the TimeSpan of the difference.
TimeSpan elapsed = now.Subtract(startDate);

// 4.
// Get number of days ago.
double daysAgo = elapsed.TotalDays;

// 5.
// Return days lapsed
return daysAgo.ToString("0");
https://www.google.lv/search?q=days lapsed c#&ie=utf-8&oe=utf-8&gws_rd=cr&ei=EztKV9qCJMOY6ASfuqKoDA#newwindow=1&q=days elapsed c#
http://www.dotnetperls.com/datetime-elapsed
 
  • Спасибо
Реакции: shabbysquire

shabbysquire

Client
Регистрация
25.11.2012
Сообщения
544
Благодарностей
26
Баллы
28
Hey Lokiys, that right there is the shizzle! 8-) Works perfectly.
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 812
Благодарностей
1 187
Баллы
113

shabbysquire

Client
Регистрация
25.11.2012
Сообщения
544
Благодарностей
26
Баллы
28
The c# worked ok in PM, but in ZP it keeps throwing up:

Код:
String was not recognized as a valid DateTime.
I think I should change the format from: 17-May-16 to one that ZP recognizes, ie: 17/05/2016
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 812
Благодарностей
1 187
Баллы
113

shabbysquire

Client
Регистрация
25.11.2012
Сообщения
544
Благодарностей
26
Баллы
28
Update:

It works ok in ZP with:

17-May-2016 (year must be full, not just: 16).
 

shabbysquire

Client
Регистрация
25.11.2012
Сообщения
544
Благодарностей
26
Баллы
28
Ok, won't work in ZP with any date format.

I've also tried:

17/05/2016.
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 812
Благодарностей
1 187
Баллы
113

shabbysquire

Client
Регистрация
25.11.2012
Сообщения
544
Благодарностей
26
Баллы
28
Tested on ZP v 5.9.8.0 works good.
What errors do you get ?
Just tried it on 5.9.8.0, but exactly same errors in ZP:

String was not recognized as a valid DateTime.

Strangely enough, it works in PM for both versions. Is it possible to use JS instead of c#?

Anyway, here is the c# that I'm using:

Код:
string someDate = "{-Variable.listing_start_date-}";
// 1.
// Parse the date and put in DateTime object.
DateTime startDate = DateTime.Parse(someDate);
// 2.
// Get the current DateTime.
DateTime now = DateTime.Now;
// 3.
// Get the TimeSpan of the difference.
TimeSpan elapsed = now.Subtract(startDate);
// 4.
// Get number of days ago.
double daysAgo = elapsed.TotalDays;
// 5.
// Return days lapsed
return daysAgo.ToString("0");
Only difference to your code, is that I use a variable in string someDate.
 

qzen4i

Client
Регистрация
01.05.2014
Сообщения
1 408
Благодарностей
314
Баллы
83
Just tried it on 5.9.8.0, but exactly same errors in ZP:

String was not recognized as a valid DateTime.

Strangely enough, it works in PM for both versions. Is it possible to use JS instead of c#?

Anyway, here is the c# that I'm using:

Код:
string someDate = "{-Variable.listing_start_date-}";
// 1.
// Parse the date and put in DateTime object.
DateTime startDate = DateTime.Parse(someDate);
// 2.
// Get the current DateTime.
DateTime now = DateTime.Now;
// 3.
// Get the TimeSpan of the difference.
TimeSpan elapsed = now.Subtract(startDate);
// 4.
// Get number of days ago.
double daysAgo = elapsed.TotalDays;
// 5.
// Return days lapsed
return daysAgo.ToString("0");
Only difference to your code, is that I use a variable in string someDate.

Код:
string someDate = project.Variables["listing_start_date"].Value;
// 1.
// Parse the date and put in DateTime object.
DateTime startDate = DateTime.Parse(someDate);
// 2.
// Get the current DateTime.
DateTime now = DateTime.Now;
// 3.
// Get the TimeSpan of the difference.
TimeSpan elapsed = now.Subtract(startDate);
// 4.
// Get number of days ago.
double daysAgo = elapsed.TotalDays;
// 5.
// Return days lapsed
return daysAgo.ToString("0");
it must be so
 
  • Спасибо
Реакции: shabbysquire

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 812
Благодарностей
1 187
Баллы
113
This is how project variables should be written in C#

C#:
project.Variables["listing_start_date"].Value
in no quotes
 
  • Спасибо
Реакции: shabbysquire

shabbysquire

Client
Регистрация
25.11.2012
Сообщения
544
Благодарностей
26
Баллы
28
Man, that's what it was. Now working like a dream! :D
 

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