Recent

Author Topic: How to set a date in TKoldateTimePicker?  (Read 6019 times)

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 168
    • http://www.jvdw.nl
How to set a date in TKoldateTimePicker?
« on: March 04, 2008, 05:04:34 pm »
Hi, using KOL-CE,

DateTimePicker1.Date:=date+10

does not seem to work

DateTimePicker1.DateTime:=date+10

does not seem to work either

How to?

tia!
John

OnixJr

  • Full Member
  • ***
  • Posts: 172
    • http://www.brlazarus.kit.net
RE: How to set a date in TKoldateTimePicker?
« Reply #1 on: March 04, 2008, 06:36:34 pm »
Try this:
Put DateUtils in uses clauses, and after do:

DateTimePicker1.Date := IncDay(DateTimePicker1.Date, 10);

See too: IncMonth, IncYear...

I don't know if it's work with Time too...
Portal Lazarus Brasil - http://lazaruspascal.codigolivre.org.br/portal.php
Lazarus BOOK (in portuguese) - http://lazarus-book.blogspot.com
<hipernetjr@yahoo.com.br> - Curitiba/Brazil

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 168
    • http://www.jvdw.nl
Re: RE: How to set a date in TKoldateTimePicker?
« Reply #2 on: March 04, 2008, 07:10:38 pm »
Quote from: "OnixJr"
Try this:
Put DateUtils in uses clauses, and after do:

DateTimePicker1.Date := IncDay(DateTimePicker1.Date, 10);

See too: IncMonth, IncYear...

I don't know if it's work with Time too...


Hi OnyxJr,

I don't think that is the problem.   I think the problem is in the procedure DateTime2SystemTime in KOL.pas.

If I use this procedure to convert today (march 4, 2008),
I get ST.wYear=109, ST.wMonth=3 and ST.wDay=6

where it *should* read wYear=2008, wMonth=3 and wDay=4

That procedure is wrong, but I just cannot figure out why... have to do some more digging....

John

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 168
    • http://www.jvdw.nl
Re: RE: How to set a date in TKoldateTimePicker?
« Reply #3 on: March 04, 2008, 09:57:04 pm »
I think, in KOL.PAS, one line should be added in the procdurebody of DateTime2SystemTime:

Code: [Select]

begin
  Days := Trunc( DateTime);
  MSec := Round((DateTime - Days) * MSecsPerDay);
 
  Days := Days+693594; // <-- add this line

  Result := False;  
  ......



It seems to work, but I'm not sure if this is the right way...

John

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 168
    • http://www.jvdw.nl
Re: RE: How to set a date in TKoldateTimePicker?
« Reply #4 on: March 04, 2008, 10:13:35 pm »
And in the last line of SystemTime2Datetime:

Code: [Select]

   DateTime := I * 365 + I div 4 - I div 100 + I div 400 + _Day -693594  // <-- number added
             + (LongInt(wHour) * 3600000 + LongInt(wMinute) * 60000 + LongInt(wSecond) * 1000 + LongInt(wMilliSeconds)) / MSecsPerDay;



To get a proper value back from DateTimePicker1.Date


But again, I'm not sure... this might break other code? Could it be that the Date-property of TKolDateTimepicker actually is treated like TTimestamp instead of TDateTime?

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 168
    • http://www.jvdw.nl
RE: Re: RE: How to set a date in TKoldateTimePicker?
« Reply #5 on: March 04, 2008, 10:51:43 pm »
And then, suddenly, the penny drops...
I had SysUtils in the uses-clause... mixing up different date and time types....

Time for a beer....