Recent

Author Topic: I need help I'm writing from turkey  (Read 11613 times)

kmalpha

  • New Member
  • *
  • Posts: 27
I need help I'm writing from turkey
« on: October 23, 2014, 02:31:25 pm »
Hello,
Check for spelling errors exposed primarily speak English. %) I want you to me the number of days between two dates that the user enters to provide information about the program finds.I did the program and I applied logic in the following way;

Code: [Select]
uses crt;
var
s2,s3,s4,day,day2,mounth,mounth2,years,years2,results:integer;
begin
write('Please enter the day of 1 Chronicles:'); readln(day);
write('1 Chronicles Enter the Month:'); readln(mounth);
write('Please enter Year 1 Chronicles:'); readln(years);
write('Please enter the day of 2 Chronicles:'); readln(day2);
write('2 Chronicles Enter the Month:'); readln(mounth2);
write('Please enter Year 1 Chronicles:'); readln(years2);
clrscr;
s2:=day-day2;
s3:=(years-years2)*365;
s4:=(mounth-mounth2)*30;
result:=s2+s3+s4;
writeln('Days :  ',result);
readln;
end.

But this one did not get the full results.Why do you say here in February I be 28 years and 4 months 31 and 30, drawn 30 days calculated without taking into account the entire month of alamıyorum.b for your help because I'm waiting for the full results.
Note: functions will not be used as dateutils
« Last Edit: October 25, 2014, 04:08:15 am by kmalpha »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: I need help I'm writing from turkey
« Reply #1 on: October 23, 2014, 02:57:27 pm »
you are supper simplifying the calculations you first need to calculate the complete years then you need to calculate the complete months for the remaining time and then calculate the days left. In each step you need to remove the calculated days by moving the start date as needed. for example start date : 1/2/2004 end date : 22/10/2014. you have 10 complete years from 1/2/2004 to 1/2/2014, and the start date becomes 1/2/20014 you 10 complete months from 1/2/2014 to 1/10/2014 and the start date becomes 1/10/2014 and 22 days from 1/10/2014 to 22/10/2014. This way you avoid calculating the leap years in between the two dates and all the other calendar changes between the years.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

derek.john.evans

  • Guest
Re: I need help I'm writing from turkey
« Reply #2 on: October 23, 2014, 03:45:34 pm »
Look in the unit DateUtils. There are functions to get the length of time between two TDateTime's. There are also functions to increment a TDateTime by a given amount.

So...

Code: Pascal  [Select][+][-]
  1. program project;
  2.  
  3. uses
  4.   DateUtils,
  5.   SysUtils;
  6.  
  7. var
  8.   LThen, LNow: TDateTime;
  9.   LYears, LMonths, LDays: Integer;
  10. begin
  11.   LThen := StrToDate('1/1/2013');
  12.   LNow := StrToDate('24/10/2014');
  13.   LYears := YearsBetween(LNow, LThen);
  14.   LThen := IncYear(LThen, LYears);
  15.   LMonths := MonthsBetween(LNow, LThen);
  16.   LThen := IncMonth(LThen, LMonths);
  17.   LDays := DaysBetween(LNow, LThen);
  18.   WriteLn(Format('Years:%d Months:%d Days:%d', [LYears, LMonths, LDays]));
  19.   ReadLn;
  20. end.  
  21.  
« Last Edit: October 02, 2015, 03:40:26 am by Geepster »

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: I need help I'm writing from turkey
« Reply #3 on: October 23, 2014, 04:16:57 pm »
You can even simplify it.

Code: [Select]
uses SysUtils, DateUtils;
...
result :=  DaysBetween(EncodeDate(Years, Month, Day), EncodeDate(Years2, Month2, Day2));

hy

  • Full Member
  • ***
  • Posts: 221
Re: I need help I'm writing from turkey
« Reply #4 on: October 23, 2014, 04:25:46 pm »
You can even simplify it.

Code: [Select]
uses SysUtils, DateUtils;
...
result :=  DaysBetween(EncodeDate(Years, Month, Day), EncodeDate(Years2, Month2, Day2));
You can even simplify more:
Code: [Select]
uses SysUtils, DateUtils;
...
result :=  EncodeDate(Years, Month, Day) - EncodeDate(Years2, Month2, Day2);
_____
***hy
OS: debian sid(64bit)  [fpc 3.20] Lazarus 2.0.12

tr_escape

  • Sr. Member
  • ****
  • Posts: 432
  • sector name toys | respect to spectre
    • Github:
Re: I need help I'm writing from turkey
« Reply #5 on: October 23, 2014, 04:38:40 pm »
Hello kmalpha,

You can use Turkish language we will try to help...

Türkçe yazın yardımcı olamaya çalışacağız.




Hello,
Check for spelling errors exposed primarily speak English. %) I want you to me the number of days between two dates that the user enters to provide information about the program finds.I did the program and I applied logic in the following way;

Code: [Select]
clrscr;
s2:=day-day2;
s3:=(years-years2)*365;
s4:=(mounth-mounth2)*30;
result:=s2+s3+s4;
writeln('Days: ',result);

But this one did not get the full results.Why do you say here in February I be 28 years and 4 months 31 and 30, drawn 30 days calculated without taking into account the entire month of alamıyorum.b for your help because I'm waiting for the full results.

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: I need help I'm writing from turkey
« Reply #6 on: October 23, 2014, 05:01:24 pm »
You can even simplify more:
Code: [Select]
uses SysUtils, DateUtils;
...
result :=  EncodeDate(Years, Month, Day) - EncodeDate(Years2, Month2, Day2);

That's true, indeed, considering how TDateTime is encoded. Though DaysBetween returns an absolute truncated value (i.e. trunc(abs())).

Anyway, I found a funny thing. Apparently, DaysBetween is a bit buggy when a date is < 30 Dec 1899 (i.e. date < 0) :

For instance, results for (month/day/year) 09/18/1822 and 09/23/1962 :

* DaysBetween : 51138
* Difference: 51139  (the correct answer).
« Last Edit: October 23, 2014, 05:16:01 pm by ChrisF »

hy

  • Full Member
  • ***
  • Posts: 221
Re: I need help I'm writing from turkey
« Reply #7 on: October 23, 2014, 06:30:18 pm »
ChrisF: Well, when it comes to historic dates there are more implications.
E.g. October 1582 should look like this (see Attachment)
_____
***hy
OS: debian sid(64bit)  [fpc 3.20] Lazarus 2.0.12

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: I need help I'm writing from turkey
« Reply #8 on: October 23, 2014, 06:45:04 pm »
Yes, I knew about this (funny) particularity of the Gregorian calendar.

Anyway, Delphi is computing correctly the difference (i.e. date<1900 and date>1900). In fact, its compute is much more simple; that's probably why it's correct.

Furthermore, 1582 is really a long time ago, while 1900 is not :-) 

Look at this news, for instance:

http://www.cnet.com/news/this-woman-had-to-lie-about-her-age-to-join-facebook/

http://www.kare11.com/story/news/local/land-of-10000-stories/2014/10/09/anna-stoehr-114-plainview-verizon/17011467/
« Last Edit: October 23, 2014, 06:48:53 pm by ChrisF »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: I need help I'm writing from turkey
« Reply #9 on: October 23, 2014, 08:15:11 pm »
ChrisF: Well, when it comes to historic dates there are more implications.
E.g. October 1582 should look like this (see Attachment)

That is country dependant, there are 3 or 4 (I only remember 2 for sure) different years in Europe alone when different countries changed to from Julian to Gregorian calendar with different day jumps as well and to top it up I have no idea if the turkish calendar has anything to do with the Gregorian calendar since most calendars are linked with the religion, so far at least.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

hy

  • Full Member
  • ***
  • Posts: 221
Re: I need help I'm writing from turkey
« Reply #10 on: October 23, 2014, 08:39:39 pm »
I know that the adoption of the gregorian calendar was on different dates all over europe.
Anyway the missing days have to be taken into account if you are calculating moonphases or star constellation or the like before  the end of 17th century.
_____
***hy
OS: debian sid(64bit)  [fpc 3.20] Lazarus 2.0.12

kmalpha

  • New Member
  • *
  • Posts: 27
Re: I need help I'm writing from turkey
« Reply #11 on: October 24, 2014, 01:51:46 am »
Merhabalar sizleri gördüğüm için mutlu oldum problemim şöyle;
Kullanıcının girdiği 2 tarih arasındaki gün farkını bulan programı yazıcam ancak şubat ayının 4 yılda bir 29 çekme olayı ve ayların 30 veya 31 çekmesi göz önününde bulundurulması lazım.Ve bu kriterleri göz önünde bulundurmadan yaptım ancak kabul olmadı benim istediğim bu kriterleri nasıl programa dökerim benim yaptığım prog. ;
Code: [Select]
uses crt;
var
s2,s3,s4,gun,gun2,ay,ay2,yil,yil2,sonuc:integer;
begin
write('1.Tarihin Gununu giriniz:'); readln(gun);
write('1.Tarihin Ayn giriniz:'); readln(ay);
write('1.Tarihin Yln giriniz:'); readln(yil);
write('2.Tarihin Gununu giriniz:'); readln(gun2);
write('2.Tarihin Ayn giriniz:'); readln(ay2);
write('2.Tarihin Yln giriniz:'); readln(yil2);
clrscr;
s2:=gun-gun2;
s3:=(yil-yil2)*365;
s4:=(ay-ay2)*30;
sonuc:=s2+s3+s4;
writeln('Aradaki gun says :  ',sonuc);
readln;
end.

Hello kmalpha,

You can use Turkish language we will try to help...

Türkçe yazın yardımcı olamaya çalışacağız.




Hello,
Check for spelling errors exposed primarily speak English. %) I want you to me the number of days between two dates that the user enters to provide information about the program finds.I did the program and I applied logic in the following way;

Code: [Select]
clrscr;
s2:=day-day2;
s3:=(years-years2)*365;
s4:=(mounth-mounth2)*30;
result:=s2+s3+s4;
writeln('Days: ',result);

But this one did not get the full results.Why do you say here in February I be 28 years and 4 months 31 and 30, drawn 30 days calculated without taking into account the entire month of alamıyorum.b for your help because I'm waiting for the full results.

kmalpha

  • New Member
  • *
  • Posts: 27
Re: I need help I'm writing from turkey
« Reply #12 on: October 24, 2014, 02:10:30 am »
Hello forum members,
First of all, thank you for your reply but I'm not allowed to use the library dateutils library or similar .This case in terms of problem solving or switch if I have to.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: I need help I'm writing from turkey
« Reply #13 on: October 24, 2014, 02:54:52 am »
Calculate how many days passed for each date, and find the difference:
Code: [Select]
  DaysPassed1 := CalcDaysPassed(gun1, ay1, yil1);
  DaysPassed2 := CalcDaysPassed(gun2, ay2, yil2);
  Answer := abs(DaysPassed1 - DaysPassed2);

How to calculate how many days passed?
1-You have "yil-1" complete years
2-And ay-1 complete months (if ay>1)
3-And gun days
Code: [Select]
DaysPassed := DaysOfCompleteYears + DaysOfCompleteMonths + gun;


kmalpha

  • New Member
  • *
  • Posts: 27
Re: I need help I'm writing from turkey
« Reply #14 on: October 24, 2014, 04:28:56 am »
Merhaba ben sizinki olmadı ben bu şeklide yaptım ancak bütün ayları 30 gün olarak hesaplattım sadece tek istediğim şubat ayının 28 çekme ve diğer ayların 30 veya 31 çekme olaylarını hesap Benim kodum;
Code: [Select]
uses crt;
var
s2,s3,s4,day,day2,mounth,mounth2,years,years2,results:integer;
begin
write('Please enter the day of 1 Chronicles:'); readln(day);
write('1 Chronicles Enter the Month:'); readln(mounth);
write('Please enter Year 1 Chronicles:'); readln(years);
write('Please enter the day of 2 Chronicles:'); readln(day2);
write('2 Chronicles Enter the Month:'); readln(mounth2);
write('Please enter Year 1 Chronicles:'); readln(years2);
clrscr;
s2:=day-day2;
s3:=(years-years2)*365;
s4:=(mounth-mounth2)*30;
result:=s2+s3+s4;
writeln('Days :  ',result);
readln;
end.

Calculate how many days passed for each date, and find the difference:
Code: [Select]
  DaysPassed1 := CalcDaysPassed(gun1, ay1, yil1);
  DaysPassed2 := CalcDaysPassed(gun2, ay2, yil2);
  Answer := abs(DaysPassed1 - DaysPassed2);

How to calculate how many days passed?
1-You have "yil-1" complete years
2-And ay-1 complete months (if ay>1)
3-And gun days
Code: [Select]
DaysPassed := DaysOfCompleteYears + DaysOfCompleteMonths + gun;

 

TinyPortal © 2005-2018