• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 874
  • Last Modified:

[Delphi] StrToDate in 64bit system

Hello my application gets data from mysql database in format: 2022-12-12
It works in all windows but only in 32 bit system. When i try to use it in 64bit windows 7 i get error:
2022-12-12 is not a valid date. My code:
Days:= Date1-StrToDate(DateFromSql);

Open in new window

What is wrong in 64 bit system?
0
l3m0n
Asked:
l3m0n
  • 2
1 Solution
 
Ephraim WangoyaCommented:

How do you get the value in the variable DateFromSql?

Instead of using a string to store the date, just store it in a real datetime variable
uses
  DateUtils;

var
    DateFromSql: TDateTime;
begin
    ....
   DateFromSql := Dataset.FieldByName('DateField').AsDateTime;

   Days := DaysBetween(Date1, DateFromSql);

  .....
0
 
l3m0nAuthor Commented:
I get it from mysql parser table not from data set:
Date:=StrToDate(UnicodeString(MYSQL_ROW^[4]));

Open in new window

i get other date too from server:
Date1 := GetURLAsString('http://www.flyffbot.pl/data.php');

Open in new window

I dont know why it works on x86 but on x64 didnt.
0
 
Ephraim WangoyaCommented:

Since you get it as string and its yyyy/mm/dd, delphi is not expecting that format when performing StrToDate

You will have to specify the format yourself

var
   F: TFormatSettings;
begin
  F.DateSeparator := '-';
  F.ShortDateFormat := 'YYYY-MM-DD';

  Days :=  Date1-StrToDate(DateFromSql, F);
 
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now