Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-05

Date value 0

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt
to Kamen Ketev
Kamen Ketev wrote
How can I use? TDateTime for date before? "12/30/1899 12:00 am". I need it for astronomical calculations. Is it possible to be add flag or something else to ignore this border??

You can use TDateTime for this, there is no problem with values < 0.

Michael.

Reply by email

Kamen Ketev

Yes but there is an error on converting date before 12/30/1899: it add 1 day. For example 27.09.1389 converts to

28.09.1389. For date after

12/30/1899 there is no problem. I am using following code:

var s, S1: string; dt: TDateTime;
      S1 := ListItem.SubItems[1]; S1 := trim(S1);
      dt := StrtoDate(s) + StrToTime(S1);
s := FormatDateTime('dd.mm.yyyy hh.nn.ss', dt);
      with Form1 do Begin
        year.Text  := copy(s, 7, 4);
      month.Text := copy(s, 4, 2);
      day.Text   := copy(s, 1, 2);
Or something wrong in my code?
Regards,
Kamen

-------- ?????????? ????? --------
??: Michael Van Canneyt
???????: Re: [Lazarus] Date value 0
??: Lazarus mailing list
????????? ??: ?????, 2015, ??? 27 10:55:23 EEST

Kamen Ketev wrote
How can I use

TDateTime for date before
"12/30/1899 12:00 am". I need it for astronomical calculations. Is it possible to be add flag or something else to ignore this border?

You can use TDateTime for this, there is no problem with values < 0.

Michael.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150527/e35ec313/attachment-0001.html>

Reply by email

Michael Schnell
to Kamen Ketev

For me it works as expcted

var t: TDateTime;
     i: integer;
     s1, s2, s3, s4 : String;
begin
t := StrToDate('30-12-1899');
i := round (t);
s1 := DateTimeToStr(t);
s2 := IntToStr(i);
t := StrToDate('29-12-1899');
i := round (t);
s3 := DateTimeToStr(t);
s4 := IntToStr(i);
Memo1.Lines.Add (s1 + '   ' + s2 + '   ' + s3 + '   ' + s4);

provides
30-12-99 0 29-12-99 -1

-Michael

Reply by email

Kamen Ketev

It works only if you don't use time. Please look at example:

var t, dt: TDateTime;
 i: integer;
 s1, s2, s3, s4, s5, s6 : String;
 begin
 t := StrToDate('30.12.1899');
 i := round (t);
 s1 := DateTimeToStr(t);
 s2 := IntToStr(i);
 t := StrToDate('29.12.1899');
 i := round (t);
 s3 := DateTimeToStr(t);
 s4 := IntToStr(i);
 dt := StrToDate('29.12.1700') + StrToTime('18:00:55');
 s5 := FormatDateTime('dd.mm.yyyy hh.nn.ss', dt);
 s6 := IntToStr(i);
 Memo1.Lines.Add (s1 + ' ' + s2 + ' ' + s3 + ' ' + s4 + ' ' + s5 + ' ' + s6);

provides
30.12.1899 0 29.12.1899 -1 30.12.1700 05.59.05 -1
Date add 1 day, time not correct

If you change date to 29.12.1900 it is ok:
30.12.1899 0 29.12.1899 -1 29.12.1900 18.00.55 -1

If you change date to 29.12.1700 and time to '8:00:55' provides: 30.12.1899 0 29.12.1899 -1 30.12.1700 15.59.05 -1

If you change date to 29.12.1900 and time to '8:00:55' provides ok:

30.12.1899 0 29.12.1899 -1 29.12.1900 08.00.55 -1
If you change date to 29.12.19 and time to '8:00:55' provides:

29.12.2019 08.00.55 -1
(not 19 year)

If you change date to 29.12.0019 and time to '8:00:55' provides: 30.12.0019 15.59.05 -1
Year is ok, but date and time not. But how I can add value in TSpinEdit 0019? I am using it because in components TDateEdit, TDateTimePicker date must be between 24.9.1752 and 31.12.9999.

If you change date to 29.12.-1900: EConvertError: not a valid date format. How can I use date before 0000 year? Regards,
Kamen

-------- ?????????? ????? --------
??: Michael Schnell
???????: Re: [Lazarus] Date value 0
??:
????????? ??: ?????, 2015, ??? 27 11:44:17 EEST

For me it works as expcted

var t: TDateTime;
     i: integer;
     s1, s2, s3, s4 : String;
begin
t := StrToDate('30-12-1899');
i := round (t);
s1 := DateTimeToStr(t);
s2 := IntToStr(i);
t := StrToDate('29-12-1899');
i := round (t);
s3 := DateTimeToStr(t);
s4 := IntToStr(i);
Memo1.Lines.Add (s1 + '   ' + s2 + '   ' + s3 + '   ' + s4);

provides

30-12-99 0 29-12-99 -1

-Michael

Reply by email

Kamen Ketev

May be using Julian day is better. Or intermediate conversion to it.

http://en.wikipedia.org/wiki/Julian_day
Regards,
Kamen

-------- ?????????? ????? --------
??: Michael Schnell
???????: Re: [Lazarus] Date value 0
??: Lazarus mailing list
????????? ??: ?????, 2015, ??? 27 11:17:06 EEST

Sven Barth wrote 9 lines
Why should that be funny? TDateTime(0.0) is defined as "12/30/1899 12:00 am". Now add two days and we are at "1/1/1900 12:00 am", so all is well...

To me (being born 12/31) it's funny that that the base is not a 1/1,

especially 1/1/0001. But of course this is completely irrelevant.

-Michael

Reply by email