Sign in Join

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

Mailing lists / fpc-pascal / 2008-09

DateTimeToFileDate

8 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Carsten Bager

When I do this

Free Pascal Compiler version 2.2.2 [2008/07/29] for i386
---------------------
Program tt;
uses dos,
     sysutils;
function strPackTime(t:longWord):shortstring;
var
  dt:Datetime;
begin
  UnpackTime(t,dt);
  strPackTime:=intToStr(dt.day)+'/'+
         intToStr(dt.month)+'-'+
         intToStr(dt.year)+
         intToStr(dt.hour)+':'+
         intToStr(dt.min)+':'+
         intToStr(dt.sec)+' ';
end;
Begin
  WriteLn(strPackTime(DateTimeToFileDate(now)));
WriteLn(DateTimeToStr(FileDateToDateTime(DateTimeToFileDate(now))))
;
End.
---------------------------------

I get this result

9/6-20160:28:22
11-9-08 13:39:55

What am I doing wrong.

Carsten

Reply by email

Mattias Gärtner
to Carsten Bager

Zitat von Carsten Bager :

When I do this Free Pascal Compiler version 2.2.2 [2008/07/29] for i386

Which OS?

Show quoted text 32 lines
--------------------- Program tt; uses dos, sysutils; function strPackTime(t:longWord):shortstring; var dt:Datetime; begin UnpackTime(t,dt); strPackTime:=intToStr(dt.day)+'/'+ intToStr(dt.month)+'-'+ intToStr(dt.year)+ intToStr(dt.hour)+':'+ intToStr(dt.min)+':'+ intToStr(dt.sec)+' '; end; Begin WriteLn(strPackTime(DateTimeToFileDate(now))); WriteLn(DateTimeToStr(FileDateToDateTime(DateTimeToFileDate(now)))) ; End. --------------------------------- I get this result 9/6-20160:28:22 11-9-08 13:39:55 What am I doing wrong.

Mattias

Reply by email

Carsten Bager
to Mattias Gärtner
Show quoted text 7 lines
Zitat von Carsten Bager : > When I do this > > Free Pascal Compiler version 2.2.2 [2008/07/29] for i386 Which OS?

Linux

Show quoted text 41 lines
> --------------------- > Program tt; > uses dos, > sysutils; > > function strPackTime(t:longWord):shortstring; > var > dt:Datetime; > begin > UnpackTime(t,dt); > strPackTime:=intToStr(dt.day)+'/'+ > intToStr(dt.month)+'-'+ > intToStr(dt.year)+ > intToStr(dt.hour)+':'+ > intToStr(dt.min)+':'+ > intToStr(dt.sec)+' '; > end; > > Begin > WriteLn(strPackTime(DateTimeToFileDate(now))); > > WriteLn(DateTimeToStr(FileDateToDateTime(DateTimeToFileDate(now)))) > ; > End. > --------------------------------- > > I get this result > > 9/6-20160:28:22 > 11-9-08 13:39:55 > > What am I doing wrong. Mattias _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Mattias Gaertner
to Carsten Bager
Show quoted text 8 lines
> Zitat von Carsten Bager : > > > When I do this > > > > Free Pascal Compiler version 2.2.2 [2008/07/29] for i386 > > Which OS? Linux

AFAIK the unit Dos should not be used under Linux.

Mattias

Show quoted text 45 lines
> > --------------------- > > Program tt; > > uses dos, > > sysutils; > > > > function strPackTime(t:longWord):shortstring; > > var > > dt:Datetime; > > begin > > UnpackTime(t,dt); > > strPackTime:=intToStr(dt.day)+'/'+ > > intToStr(dt.month)+'-'+ > > intToStr(dt.year)+ > > intToStr(dt.hour)+':'+ > > intToStr(dt.min)+':'+ > > intToStr(dt.sec)+' '; > > end; > > > > Begin > > WriteLn(strPackTime(DateTimeToFileDate(now))); > > > > WriteLn(DateTimeToStr(FileDateToDateTime(DateTimeToFileDate(now)))) > > ; > > End. > > --------------------------------- > > > > I get this result > > > > 9/6-20160:28:22 > > 11-9-08 13:39:55 > > > > What am I doing wrong. > > > Mattias > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Carsten Bager
to Mattias Gaertner
AFAIK the unit Dos should not be used under Linux. Mattias

I rewrote the code omitting the dos unit, and got the fowing. In my opinion the windows output and the Linux output should be (almost) the same, and then my conclusion is a compiler/rtl error. Do you agree (I have also tested the 2.2.0 compiler and got the same result).

Carsten

Output from Linux compiler

Free Pascal Compiler version 2.2.0 [2007/08/31] for i386 Target OS: Linux for i386
12/6-2016 25:14:58
14-9-08 10:22:53

Output from Windows Compiler
Free Pascal Compiler version 2.2.2 [2008/08/03] for i386 Target OS: Win32 for i386

14/9-2008 10:21:42
14-09-2008 10:21:42

----------------------------------

Program tt;
uses sysutils;
Type
   Datetime_typ=Packed record
      year,month,day,hour,min,sec,sec100,dayOfWeek:word;
   end;
procedure UnpackTime(pdt:LongWord; var d:dateTime_typ);
begin
  d.sec:=(pdt and 31) *2;
  pdt:=pdt shr 5;
  d.min:=pdt and 63;
  pdt:=pdt shr 6;
  d.hour:=pdt and 31;
  pdt:=pdt shr 5;
  d.day:=pdt and 31;
  pdt:=pdt shr 5;
  d.month:=pdt and 15;
  pdt:=pdt shr 4;
  d.year:=pdt+1980;
end;
function strPackTime(t:longWord):shortstring;
var
  dt:Datetime_typ;
begin
  UnpackTime(t,dt);
  strPackTime:=intToStr(dt.day)+'/'+
         intToStr(dt.month)+'-'+
         intToStr(dt.year)+' '+
         intToStr(dt.hour)+':'+
         intToStr(dt.min)+':'+
         intToStr(dt.sec)+' ';
end;
Begin
  WriteLn(strPackTime(DateTimeToFileDate(now)));

WriteLn(DateTimeToStr(FileDateToDateTime(DateTimeToFileDate(now)))) ;
End.
------------------------------------
Med venlig hilsen
Carsten Bager

BEAS A/S
Brørupvænget 10
DK-7650 Bøvlingbjerg
Tlf. : +45 9788 5222 Fax : +45 9788 5434
www.beas.dk

Reply by email

Mattias Gaertner
to Carsten Bager
Show quoted text 10 lines
> AFAIK the unit Dos should not be used under Linux. > > > Mattias I rewrote the code omitting the dos unit, and got the fowing. In my opinion the windows output and the Linux output should be (almost) the same, and then my conclusion is a compiler/rtl error. Do you agree (I have also tested the 2.2.0 compiler and got the same result).

The FileDate format differ on unix and windows. UnpackTime uses the windows format. You need another function for unix.

Mattias

Show quoted text 77 lines
Carsten Output from Linux compiler Free Pascal Compiler version 2.2.0 [2007/08/31] for i386 Target OS: Linux for i386 12/6-2016 25:14:58 14-9-08 10:22:53 Output from Windows Compiler Free Pascal Compiler version 2.2.2 [2008/08/03] for i386 Target OS: Win32 for i386 14/9-2008 10:21:42 14-09-2008 10:21:42 ---------------------------------- Program tt; uses sysutils; Type Datetime_typ=Packed record year,month,day,hour,min,sec,sec100,dayOfWeek:word; end; procedure UnpackTime(pdt:LongWord; var d:dateTime_typ); begin d.sec:=(pdt and 31) *2; pdt:=pdt shr 5; d.min:=pdt and 63; pdt:=pdt shr 6; d.hour:=pdt and 31; pdt:=pdt shr 5; d.day:=pdt and 31; pdt:=pdt shr 5; d.month:=pdt and 15; pdt:=pdt shr 4; d.year:=pdt+1980; end; function strPackTime(t:longWord):shortstring; var dt:Datetime_typ; begin UnpackTime(t,dt); strPackTime:=intToStr(dt.day)+'/'+ intToStr(dt.month)+'-'+ intToStr(dt.year)+' '+ intToStr(dt.hour)+':'+ intToStr(dt.min)+':'+ intToStr(dt.sec)+' '; end; Begin WriteLn(strPackTime(DateTimeToFileDate(now))); WriteLn(DateTimeToStr(FileDateToDateTime(DateTimeToFileDate(now)))) ; End. ------------------------------------ Med venlig hilsen Carsten Bager BEAS A/S Brørupvænget 10 DK-7650 Bøvlingbjerg Tlf. : +45 9788 5222 Fax : +45 9788 5434 www.beas.dk _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Jonas Maebe
to Carsten Bager
Carsten Bager wrote 6 lines
> The FileDate format differ on unix and windows. UnpackTime uses the > windows format. You need another function for unix. Is the file date on Unix the number of seconds since 00:00:00 January 1, 1970.

Yes, and you also still have to adjust for the current time zone. It's probably easier to just use the regular rtl routines. If you want to program it yourself, search for datetime in rtl/unix/sysutils.pp

Jonas

Reply by email