[Delphi] StrToDate in 64bit system

Posted on 2011-04-26
Last Modified: 2012-05-11
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?
Question by:l3m0n
    LVL 32

    Expert Comment


    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

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

       Days := DaysBetween(Date1, DateFromSql);


    Author Comment

    I get it from mysql parser table not from data set:

    Open in new window

    i get other date too from server:
    Date1 := GetURLAsString('');

    Open in new window

    I dont know why it works on x86 but on x64 didnt.
    LVL 32

    Accepted Solution


    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

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

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

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video discusses moving either the default database or any database to a new volume.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now