How to Calculate Difference Between 2 Dates ?

ninny83

Client
Регистрация
10.05.2011
Сообщения
86
Благодарностей
8
Баллы
0
Hello guys,

How can I calculate the difference between a date in this format 11/25/2012 09:27:16 and today?

Thank you!
 

ninny83

Client
Регистрация
10.05.2011
Сообщения
86
Благодарностей
8
Баллы
0

shabbysquire

Client
Регистрация
25.11.2012
Сообщения
544
Благодарностей
26
Баллы
28
I realize this was asked back in '12, but did you find a solution to this? I'm also trying to work with dates in ZP.

For example, I take a date from a Fiverr gig, say 2012/5/1. I'd need to first work out how many days (or months) from gig creation to today. Then second step to set my own parameter, i.e. if gig created within last 90-days then keep. If gig is outside 90-days, then discard.

I suspect I'll need to use extra code to perform this, but thought I'd ask here first.
 

nevadahsot

Client
Регистрация
27.04.2012
Сообщения
106
Благодарностей
5
Баллы
18
{-TimeNow.Date-}
Google "calculate days"
 

bigcajones

Client
Регистрация
09.02.2011
Сообщения
1 216
Благодарностей
683
Баллы
113
Код:
string someDate = project.Variables["beginningDate"].Value;
DateTime startDate = DateTime.Parse(someDate);
DateTime now = DateTime.Now;
TimeSpan elapsed = now.Subtract(startDate);
double daysAgo = elapsed.TotalDays;
var totelapsed = daysAgo.ToString("0");
return totelapsed;
Посмотреть вложение timeElapsed.xmlz
 
  • Спасибо
Реакции: shabbysquire

shabbysquire

Client
Регистрация
25.11.2012
Сообщения
544
Благодарностей
26
Баллы
28
That's a nifty solution Bigcajones, thanks!

I input the dates in various formats (i.e. 2012/3/3 or 3/3/2012) and it managed to calculate the correct no of days elapsed.
 

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