Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8251407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:13:38+00:00 2026-06-08T00:13:38+00:00

Delphi has this function: function VarToDateAsString(const V: TVarData): TDateTime; …. LResult := VarDateFromStr(S, VAR_LOCALE_USER_DEFAULT,

  • 0

Delphi has this function:

function VarToDateAsString(const V: TVarData): TDateTime;
....
LResult := VarDateFromStr(S, VAR_LOCALE_USER_DEFAULT, 0, Result);

doing this with today’s date:

   VarDateFromStr('07;12;18', VAR_LOCALE_USER_DEFAULT, 0, Result);

then Result will be equal

Result = '07;18;12'

Is any fix possible ?

CODE EXAMPLE

procedure TForm1.Button1Click(Sender: TObject);
var
  LDateTimeVar: Variant;
  LDateTime: TDateTime;
begin
  // Current date separator in OS settings is ';'
  LDateTimeVar := '07;12;18';
  LDateTime := VarToDateTime(LDateTimeVar);
  // Expected LDateTime = '07;12;18', 
  // but will be LDateTime = '07;18;12'  
  ShowMessage(DateToStr(LDateTime));
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:13:40+00:00Added an answer on June 8, 2026 at 12:13 am

    VarToDateAsString calls ‘oleaut32’s VarDateFromStr to perform the conversion, which simply fails if you’ve got the year in the middle.

    variants.VarToDateAsString:

    function VarToDateAsString(const V: TVarData): TDateTime;
    var
      ...
    begin
      _VarToWStr(S, V);
      LResult := VarDateFromStr(S, VAR_LOCALE_USER_DEFAULT, 0, Result);
      ...
    

    Put a breakpoint on the second line and you’ll see the Result parameter will reverse the day and the year. You can carry out tests yourself by calling activex.VarDateFromStr.

    You can bypass variants.VarToDateAsString calling VarDateFromStr and implement your own function, but don’t think using something from sysutils because it doesn’t support a year-in the middle format too. sysutils.TryStrToDateTime calls ScanDate which in turn calls GetDateOrder. The below is the entire function:

    function GetDateOrder(const DateFormat: string): TDateOrder;
    var
      I: Integer;
    begin
      Result := doMDY;
      I := 1;
      while I <= Length(DateFormat) do
      begin
        case Chr(Ord(DateFormat[I]) and $DF) of
          'E': Result := doYMD;
          'Y': Result := doYMD;
          'M': Result := doMDY;
          'D': Result := doDMY;
        else
          Inc(I);
          Continue;
        end;
        Exit;
      end;
    end;
    

    As you can see there’s no outcome ordering with year in the middle.

    Looks like you have to parse the string yourself:

    uses
      varutils;
    
    function MyVarDateFromStr(const strIn: WideString; LCID: DWORD; dwFlags: Longint;
      out dateOut: TDateTime): HRESULT; stdcall;
    begin
      // write your parser here and return a valid 'dateOut'
    end;
    
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      LDateTimeVar: Variant;
      LDateTime: TDateTime;
    begin
      varutils.VarDateFromStr := MyVarDateFromStr;   // replace the broken function
    
      // Current date separator in OS settings is ';'
      LDateTimeVar := '07;12;18';
      LDateTime := VarToDateTime(LDateTimeVar);
      // Expected LDateTime = '07;12;18',
      // but will be LDateTime = '07;18;12'
      ShowMessage(DateToStr(LDateTime));
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using this code for md5 hashing in Delphi 7: function MD5(const fileName
Delphi 2010 has a nice set of new file access functions in IOUtils.pas (I
I have a Delphi application that has a document browser as the main form.
I am using Delphi 2009 which has the FastMM4 memory manager built into it.
I'm writing a tcp client in Delphi for a server that has a series
When I compile our project use Delphi 2010 Trial, there has a fatal error
Are there any CI-Systems for Delphi like Hudson for Java? Does Hudson has any
// delphi code (delphi version : Turbo Delphi Explorer (it's Delphi 2006)) function GetLoginResult:PChar;
I am trying to learn inline assembly programming in Delphi, and to this end
I'm was trying to write a dll library in Delphi wih a function that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.