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 какие-либо сделки.

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
 
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
Hey Lokiys, that right there is the shizzle! 8-) Works perfectly.
 
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
 
Update:

It works ok in ZP with:

17-May-2016 (year must be full, not just: 16).
 
Ok, won't work in ZP with any date format.

I've also tried:

17/05/2016.
 
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.
 
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
This is how project variables should be written in C#

C#:
Развернуть Свернуть Копировать
project.Variables["listing_start_date"].Value
in no quotes
 
  • Спасибо
Реакции: shabbysquire
Man, that's what it was. Now working like a dream! :D
 

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