Sign in Join

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

Mailing lists / fpc-pascal / 2001-03

Question about DATE handling...

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Rainer Hantsch

Hello, everybody!

For a CGI program (Linux), I need some date conversions/calculations, but I have some difficulties.

All of the remaining project is compiled in TurboPascal Mode (no options like ObjFPC or Delphi specified in FPC 1.0.4).

Here my problems:
-----------------
If I convert a date string (dd.mm.yyyy) into a numeric value, StrToDate() has difficulties and causes an EConvertError, if the data are not right. Michawl suggested to add an "except ... end;" part to this conversion, but then my compiler sais that it needs either ObjFPC or Delphi mode. (But this compiles the while stuff of the remaining project differently!) So i cannot use this. --> Any idea on how to overcome this?

Next, the result of StrToDate() is tDateTime. I can basically live with this, but: How can I add a specific number of days to this date? (I must calculate a end date from start-date plus num of days!)
Normally, I use EpochTime as internal date format for all of that, so I can simply add/subtract seconds -- and this is perfect. --> But how can I get an epoch time out from tDateTime?

Please, leave me an urgent note on that, I stuck.

Ing. Rainer Hantsch

\\|// Ing. Rainer HANTSCH - Hardware + Software (o o) Your Partner - Your Supplier - Your Friend! --oOOo-(_)-oOOo-------------------------------------------------- Ing. Rainer HANTSCH | e-Mail:
Khunngasse 21/20 | www : http://www.hantsch.co.at A-1030 Vienna | Tel. : ++43 - 1 - 7988538 0 ---------------------| Fax : ++43 - 1 - 7988538 18 ** AUSTRIA ** | Mobile: ++43 - 663 - 9194382 -----------------------------------------------------------------

Reply by email

Matt Emson
Next, the result of StrToDate() is tDateTime. I can basically live with this, but: How can I add a specific number of days to this date? (I must calculate

a

end date from start-date plus num of days!)

TDateTime (if it works like the Delphi type of the same name) works in the following way..

TDateTime = Double;

The part before the Decimal point is the date, the part after is the 'time'.

Date:

var
  T: TDateTime;
begin
  T := 0; // 30/12/1899 (Delphi 2+)
  T := 1; // 31/12/1899
end;
  you can therefore summise that each whole digit = 1 day.
  therefore, 'today' = number of days since 30/12/1899

Time:
0.000012 = 1 second (00:00:01)
0.000024 = 2 seconds (00:00:02)

Normally, I use EpochTime as internal date format for all of that, so I can simply add/subtract seconds -- and this is perfect. --> But how can I get an epoch time out from tDateTime?

Take a look at:

http://www.merlyn.demon.co.uk/pas-time.htm

Hope that helps,

Matt

Reply by email

greim
to Rainer Hantsch: Hello, everybody! For a CGI program (Linux), I need some date conversions/calculations,…

Hi Rainer,

enclosed a unit i often use. Its quite old, based on some C-code published in the c't magazine years ago.
I hope thats not a (c) violation.
I use the time from 01.01.1980 becaus longint
has only half the time as epoch time...

Regards

Markus Greim

Rainer Hantsch wrote 42 lines
Hello, everybody! For a CGI program (Linux), I need some date conversions/calculations, but I have some difficulties. All of the remaining project is compiled in TurboPascal Mode (no options like ObjFPC or Delphi specified in FPC 1.0.4). Here my problems: ----------------- If I convert a date string (dd.mm.yyyy) into a numeric value, StrToDate() has difficulties and causes an EConvertError, if the data are not right. Michawl suggested to add an "except ... end;" part to this conversion, but then my compiler sais that it needs either ObjFPC or Delphi mode. (But this compiles the while stuff of the remaining project differently!) So i cannot use this. --> Any idea on how to overcome this? Next, the result of StrToDate() is tDateTime. I can basically live with this, but: How can I add a specific number of days to this date? (I must calculate a end date from start-date plus num of days!) Normally, I use EpochTime as internal date format for all of that, so I can simply add/subtract seconds -- and this is perfect. --> But how can I get an epoch time out from tDateTime? Please, leave me an urgent note on that, I stuck. Ing. Rainer Hantsch \\|// Ing. Rainer HANTSCH - Hardware + Software (o o) Your Partner - Your Supplier - Your Friend! --oOOo-(_)-oOOo-------------------------------------------------- Ing. Rainer HANTSCH | e-Mail: Khunngasse 21/20 | www : http://www.hantsch.co.at A-1030 Vienna | Tel. : ++43 - 1 - 7988538 0 ---------------------| Fax : ++43 - 1 - 7988538 18 ** AUSTRIA ** | Mobile: ++43 - 663 - 9194382 ----------------------------------------------------------------- _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email