Sign in Join

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

Mailing lists / lazarus / 2016-07

date function db_date();

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Larry Dalton

I use the following function to read a date from a Libre Office dbase file. The field is stored as

a string, ie '04/08/2016'.

function db_date(const dog_base:tdbf;const t_field:string):tdatetime;
var test_date:tdatetime;
test_bool:boolean;
test_string:string;

begin {starts function db_date(const dog_base:tdbf;const t_field:string):tdatetime;}

test_bool:=dog_base.FieldByName(t_field).Valuenull;
if test_bool then test_date:=dog_base.FieldByName(t_field).AsDateTime
else test_date:=now;
result:=test_date;

end; {ends function db_date(const dog_base:tdbf;const t_field:string):tdatetime;}

I am running lazarus 1.6, on both Windows 8 and Linux Mint 17. The above function works fine on the Windows 8 box, but on the Linux Mint box, I get the following error: “04/08/2016” is not a valid date format. Why does it work on Windows but not Linux? How can I rewrite it to work on both? -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160704/939a1da6/attachment.html>

Reply by email

Michael Van Canneyt
to Larry Dalton
Larry Dalton wrote 32 lines
I use the following function to read a date from a Libre Office dbase file. The field is stored as a string, ie '04/08/2016'. function db_date(const dog_base:tdbf;const t_field:string):tdatetime; var test_date:tdatetime; test_bool:boolean; test_string:string; begin {starts function db_date(const dog_base:tdbf;const t_field:string):tdatetime;} test_bool:=dog_base.FieldByName(t_field).Valuenull; if test_bool then test_date:=dog_base.FieldByName(t_field).AsDateTime else test_date:=now; result:=test_date; end; {ends function db_date(const dog_base:tdbf;const t_field:string):tdatetime;} I am running lazarus 1.6, on both Windows 8 and Linux Mint 17. The above function works fine on the Windows 8 box, but on the Linux Mint box, I get the following error: “04/08/2016” is not a valid date format. Why does it work on Windows but not Linux? How can I rewrite it to work on both?

under linux, add the clocale unit to the uses clause of your project. Make sure that the locale is set to the correct locale.

Alternatively, set
   DefaultFormatSettings.ShortDateFormat:='dd/mm/yyyy';
   DefaultFormatSettings.DateSeparator:='/';
at the start of your program or input routine.

Yet another way would be to use the scandatetime function

test_date:=scanDateTime('dd/mm/yyyy',dog_base.FieldByName(t_field).AsString);

See
http://www.freepascal.org/docs-html/rtl/dateutils/scandatetime.html

Michael.

Reply by email

Larry Dalton

I use the following function to read a date from a Libre Office dbase file. The field is stored as a string, ie '04/08/2016'.

function db_date(const dog_base:tdbf;const t_field:string):tdatetime;
var test_date:tdatetime;
test_bool:boolean;
test_string:string;
begin {starts function db_date(const dog_base:tdbf;const t_field:string):tdatetime;}
test_bool:=dog_base.FieldByName(t_field).Valuenull;
if test_bool then test_date:=dog_base.FieldByName(t_field).AsDateTime
else test_date:=now;
result:=test_date;
end; {ends function db_date(const dog_base:tdbf;const t_field:string):tdatetime;}
I am running lazarus 1.6, on both Windows 8 and Linux Mint 17. The above function works fine on the Windows 8 box, but on the Linux Mint box, I get the following error: “04/08/2016” is not a valid date format. Why does it work on Windows but not Linux? How can I rewrite it to work on both?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160705/18b1ea52/attachment.html>

Reply by email

Larry Dalton

I use the following function to read a date from a Libre Office dbase file. The field is stored as a string, ie '04/08/2016'.

function db_date(const dog_base:tdbf;const t_field:string):tdatetime;
var test_date:tdatetime;
test_bool:boolean;
test_string:string;
begin {starts function db_date(const dog_base:tdbf;const t_field:string):tdatetime;}
test_bool:=dog_base.FieldByName(t_field).Valuenull;
if test_bool then test_date:=dog_base.FieldByName(t_field).AsDateTime
else test_date:=now;
result:=test_date;
end; {ends function db_date(const dog_base:tdbf;const t_field:string):tdatetime;}
I am running lazarus 1.6, on both Windows 8 and Linux Mint 17. The above function works fine on the Windows 8 box, but on the Linux Mint box, I get the following error: “04/08/2016” is not a valid date format. Why does it work on Windows but not Linux? How can I rewrite it to work on both?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160705/7b71d5ba/attachment.html>

Reply by email

John Landmesser
to Larry Dalton
Larry Dalton wrote 37 lines
I use the following function to read a date from a Libre Office dbase file. The field is stored as a string, ie '04/08/2016'. function db_date(const dog_base:tdbf;const t_field:string):tdatetime; var test_date:tdatetime; test_bool:boolean; test_string:string; begin {starts function db_date(const dog_base:tdbf;const t_field:string):tdatetime;} test_bool:=dog_base.FieldByName(t_field).Valuenull; if test_bool then test_date:=dog_base.FieldByName(t_field).AsDateTime else test_date:=now; result:=test_date; end; {ends function db_date(const dog_base:tdbf;const t_field:string):tdatetime;} I am running lazarus 1.6, on both Windows 8 and Linux Mint 17. The above function works fine on the Windows 8 box, but on the Linux Mint box, I get the following error: “04/08/2016” is not a valid date format. Why does it work on Windows but not Linux? How can I rewrite it to work on both?

I think thats due to "locales" defined the right way on Windows, but differs on Linux.

Have a look at:

http://www.freepascal.org/docs-html/rtl/sysutils/dateseparator.html

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160706/a59cd674/attachment.html>

Reply by email

Larry Dalton
to John Landmesser

Apparently that is the problem.

Sent from my iPhone

Show quoted text 30 lines
On Jul 6, 2016, at 10:43, John Landmesser wrote: > On 05.07.2016 19:20, Larry Dalton wrote: > I use the following function to read a date from a Libre Office dbase file. The field is stored as > a string, ie '04/08/2016'. > > function db_date(const dog_base:tdbf;const t_field:string):tdatetime; > var test_date:tdatetime; > test_bool:boolean; > test_string:string; > begin {starts function db_date(const dog_base:tdbf;const t_field:string):tdatetime;} > test_bool:=dog_base.FieldByName(t_field).Valuenull; > if test_bool then test_date:=dog_base.FieldByName(t_field).AsDateTime > else test_date:=now; > result:=test_date; > end; {ends function db_date(const dog_base:tdbf;const t_field:string):tdatetime;} > I am running lazarus 1.6, on both Windows 8 and Linux Mint 17. The above function works fine on the Windows 8 box, but on the Linux Mint box, I get the following error: “04/08/2016” is not a valid date format. Why does it work on Windows but not Linux? How can I rewrite it to work on both? I think thats due to "locales" defined the right way on Windows, but differs on Linux. Have a look at: http://www.freepascal.org/docs-html/rtl/sysutils/dateseparator.html -- _______________________________________________ Lazarus mailing list http://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160706/24e9aeb6/attachment.html>

Reply by email

Larry Dalton
to John Landmesser: I think thats due to "locales" defined the right way on Windows, but differs on Linux.…

Thanks, John. That worked.

Sent from my iPhone

Show quoted text 30 lines
On Jul 6, 2016, at 10:43, John Landmesser wrote: > On 05.07.2016 19:20, Larry Dalton wrote: > I use the following function to read a date from a Libre Office dbase file. The field is stored as > a string, ie '04/08/2016'. > > function db_date(const dog_base:tdbf;const t_field:string):tdatetime; > var test_date:tdatetime; > test_bool:boolean; > test_string:string; > begin {starts function db_date(const dog_base:tdbf;const t_field:string):tdatetime;} > test_bool:=dog_base.FieldByName(t_field).Valuenull; > if test_bool then test_date:=dog_base.FieldByName(t_field).AsDateTime > else test_date:=now; > result:=test_date; > end; {ends function db_date(const dog_base:tdbf;const t_field:string):tdatetime;} > I am running lazarus 1.6, on both Windows 8 and Linux Mint 17. The above function works fine on the Windows 8 box, but on the Linux Mint box, I get the following error: “04/08/2016” is not a valid date format. Why does it work on Windows but not Linux? How can I rewrite it to work on both? I think thats due to "locales" defined the right way on Windows, but differs on Linux. Have a look at: http://www.freepascal.org/docs-html/rtl/sysutils/dateseparator.html -- _______________________________________________ Lazarus mailing list http://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160708/1d6a1d45/attachment.html>

Reply by email